intmain(){ unordered_map<int,int> mp; int n; cin>>n; vector<int> a(n); int k = 0; for(int i=0;i<n;i++) { scanf("%d", &a[i]); k = max(k, a[i]); }
int res = 0, num = 0; for(int i=2;i<=k;i++){ for(int j=0;j<n;j++) { if(a[j] % i==0) mp[i]++; } if(mp[i] > num){ num = mp[i]; res = i; } } cout<<res<<endl; return0; }
C - To 3 let k be the number of digits in N. Want to make N a multiple of 3 by erasing 0~k-1 digits. Return the minimum number of digits moved to achieve that.
intmain(){ longlong n; cin>>n; unordered_map<int,int> mp; int k =0, s = 0; while(n){ int c = n%10; mp[c%3] ++; s += c; n/=10; k++; } if(s%3==0) cout<<0<<endl; elseif(s%3==1) { int res = k+1; if(mp[1]>=1 && k>1) res = 1; if(mp[2]>=2 && k>2) res = min(res, 2); if(res==k+1) res = -1; cout<<res<<endl; }else{ int res = k+1; if(mp[2]>=1 && k>1) res = 1; if(mp[1]>=2 && k>2) res = min(res, 2); if(res==k+1) res = -1; cout<<res<<endl; } return0;
}
D - Wandering Given a sequence A_1 to A_n; Move A1; Move A1, then move A2; … Move A1, then move A2, … move A_n; Find the most positive coordinate in the process.
intmain(){ int n; cin>>n; LL sum = 0, x = 0, mx = 0; LL res = 0; for(int i=0;i<n;i++){ LL a; scanf("%lld", &a); mx = max(mx, x + a); x += a; res = max(res, sum + mx); sum += x; } cout<<res<<endl; return0; }
E - Akari Given a 2D-grid, there are N bulbs and M blocks on this grid. Every bulb emits beams of in 4 directions, which can illuminate grids on the way, until reaching a block. Find the number of grids illuminated. Solution: The number of bulbs is too large. Should enumerate all the grids directly, and mark those which are illuminated.