Link ARC 063 top page Editorial C – 一次元リバーシ / 1D Reversi Problem
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

/* * AC 6 ms 512 KB */ #include <cstdio> #include <iostream> using namespace std; int main(){ //freopen("c.in", "r", stdin); string s; cin >> s; int ans = 0; for (int i = 0; i < s.size()  1; ++i) { if (s[i] != s[i+1]) ans++; } printf("%d\n", ans); return 0; } 
D – 高橋君と見えざる手 / An Invisible Hand Problem I didn’t notice that there is a restriction that each \(A_i \) is different. So it took time for implementation.
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

/* * AC 15 ms 640 KB */ #include <cstdio> #include <iostream> using namespace std; #define INF 1e9; int a[100005]; int N, T; int maxDiff = 0; int main(){ //freopen("d3.in", "r", stdin); scanf("%d %d", &N, &T); int tmpmin = INF; for (int i = 0; i < N; ++i) { scanf("%d", &a[i]); if (tmpmin > a[i]) tmpmin = a[i]; int diff = a[i]  tmpmin; if (diff > maxDiff) maxDiff = diff; } int minCount = 0, maxCount = 0; tmpmin = INF; int ans = 0; for (int i = 0; i < N; ++i) { if (tmpmin + maxDiff == a[i]) maxCount++; if (tmpmin == a[i]) { minCount++; } else if (tmpmin > a[i]) { // update tmpmin = a[i]; ans += min(minCount, maxCount); // reinit minCount = 1; maxCount = 0; } } ans += min(minCount, maxCount); printf("%d\n", ans); return 0; } 
E – 木と整数 / Integers on a Tree Problem Follow […]
Continue reading →