0%

AtCoder 182

A - twiblr

twiblr.cppview raw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
#include <vector>
#include <queue>
#include <cstring>
#include <algorithm>
#include <string>
#include <unordered_set>
using namespace std;

int main(){
int A, B;
cin>>A>>B;
cout<< 2 * A + 100 - B <<endl;
return 0;
}

B - Almost GCD
GCD-ness of k is the number of elements among A_1 to A_n divisible k.
Print the most GCD-ness number greater than or equal to 2;

almost-gcd.cppview raw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <iostream>
#include <vector>
#include <queue>
#include <cstring>
#include <algorithm>
#include <string>
#include <unordered_set>
#include <unordered_map>
using namespace std;

const int INF = 1e9;

int main(){
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;
return 0;
}

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.

to-3.cppview raw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <iostream>
#include <vector>
#include <queue>
#include <cstring>
#include <algorithm>
#include <string>
#include <unordered_set>
#include <unordered_map>
#include <cstring>
using namespace std;


int main(){
long long 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;
else if(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;
}
return 0;

}

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.

wandering.cppview raw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <iostream>
#include <vector>
#include <queue>
#include <cstring>
#include <algorithm>
#include <string>
#include <unordered_set>
#include <unordered_map>
using namespace std;

typedef long long LL;
const int INF = 0x3f3f3f3f;

int main(){
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;
return 0;
}

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.

akari.cppview raw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <iostream>
#include <vector>
#include <queue>
#include <cstring>
#include <algorithm>
#include <string>
#include <unordered_set>
#include <unordered_map>
#include <cstring>
using namespace std;

typedef long long LL;
typedef pair<int,int> PII;
int h, w;
int n, m;
const int N = 1510;
int g[N][N];


int main(){
cin>>h>>w>>n>>m;
for(int i=0;i<n;i++){
int a, b;
scanf("%d%d", &a,&b);
g[a][b] = 1;
}
for(int i=0;i<m;i++){
int a, b;
scanf("%d%d", &a, &b);
g[a][b] = -1;
}
int res = 0;
for(int i=1;i<=h;i++){
bool flag = false;
for(int j=1;j<=w;j++){
if(g[i][j]==-1) flag = false;
else if(g[i][j]==1) flag = true;
else if(flag) g[i][j] = 2;
}
flag = false;
for(int j=w;j>=1;j--){
if(g[i][j]==-1) flag = false;
else if(g[i][j]==1) flag = true;
else if(flag) g[i][j] = 2;
}
}
for(int j=1;j<=w;j++){
bool flag = false;
for(int i=1;i<=h;i++){
if(g[i][j]==-1) flag = false;
if(g[i][j]==1) flag = true;
else if(flag) g[i][j] = 2;
}
flag = false;
for(int i=h;i>=1;i--){
if(g[i][j]==-1) flag = false;
if(g[i][j]==1) flag = true;
else if(flag) g[i][j] = 2;
}
}
for(int i=1;i<=h;i++)
for(int j=1;j<=w;j++)
res += g[i][j] > 0;
cout<<res<<endl;
return 0;
}

F - Valid payments