C++の練習を兼ねて, AtCoder Regular Contest 040 の 問題A (床塗り) ~ 問題B (直線塗り) を解いてみた.
■感想.
1. 問題B は, 実装に苦労したものの, 何とかAC版となった.
2. 時間を見つけて, 引き続き, 過去問を振り返っていきたいと思う.
本家のサイトARC 040 解説をご覧下さい.
■C++版プログラム(問題A/AC版).
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 |
#include <bits/stdc++.h> using namespace std; #define repex(i, a, b, c) for(int i = a; i < b; i += c) #define repx(i, a, b) repex(i, a, b, 1) #define rep(i, n) repx(i, 0, n) #define repr(i, a, b) for(int i = a; i >= b; i--) int main(){ // 1. 入力情報. int N; scanf("%d", &N); // 2. 勝敗チェック. int r = 0, b = 0; rep(i, N){ char c[111]; scanf("%s", c); rep(j, N){ if(c[j] == 'R') r++; if(c[j] == 'B') b++; } } // 3. 出力. string ans = "DRAW"; if(r > b) ans = "TAKAHASHI"; if(r < b) ans = "AOKI"; printf("%s\n", ans.c_str()); return 0; } |
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 |
[入力例] 4 R.RB RR.B BRBB RRB. [出力例] TAKAHASHI ※AtCoderのテストケースより [入力例] 2 .. .. [出力例] DRAW ※AtCoderのテストケースより [入力例] 3 BRB RBR BRB [出力例] AOKI ※AtCoderのテストケースより [入力例] 7 R.....B RR...BB R.R.B.B R..B..B R.B.R.B RB...RB B.....R [出力例] AOKI |
■C++版プログラム(問題B/AC版).
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 |
#include <bits/stdc++.h> using namespace std; #define repex(i, a, b, c) for(int i = a; i < b; i += c) #define repx(i, a, b) repex(i, a, b, 1) #define rep(i, n) repx(i, 0, n) #define repr(i, a, b) for(int i = a; i >= b; i--) int memo[1010]; int main(){ // 1. 入力情報. int N, R; char c[1010]; scanf("%d %d %s", &N, &R, c); // 2. すべてのマスを塗るための時間の最小値は? int i = N, maxP = 0; while(--i >= 0){ if(c[i] == '.'){ // 射程を考慮. i -= (R - 1); // index更新. i = max(0, i); // 最大値更新. maxP = max(maxP, i); // 現在位置保存. memo[i] = 1; // 次処理へ. continue; } } // 3. 出力. // rep(i, N) printf("%d ", memo[i]); // puts(""); int ans = maxP; rep(i, N) if(memo[i]) ans++; printf("%d\n", ans); return 0; } |
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 |
[入力例] 7 3 ...o.o. [出力例] 6 ※AtCoderのテストケースより [入力例] 8 4 ...o.ooo [出力例] 3 ※AtCoderのテストケースより [入力例] 4 4 oooo [出力例] 0 ※AtCoderのテストケースより [入力例] 77 5 ...o.o.o.o....o.oo.o..o...o.oo..o.ooo...o.o...o.ooooo...o.ooo...o.o.o...o.o.o [出力例] 83 [入力例] 500 12 ..oooo...oo.oo..o..o..o..oo......oo.o.oo..o.oooo..o....o.oo.o..o.o..oooo..ooo..oo.o.oooo.ooooo..oooo..ooooo.o..o...o......ooo..o...oo.o..oo...o...oo...o.o........o...oo.o...o.o.oooo.ooo..o.oooo.oo.ooo.o.oooo...o.ooo...o.o....o.oo.ooo...o..oooo.oo...oo..oo.oo.oo..o...o...oo...o....oo.o.o.ooo.o.oo.o.ooo.o..o.oooo.....o.oo.ooo.ooo.o.o.....o...o..o.oooooo.....o.oooo...o..oooo.ooo.....oooooooooo.ooo...o.oo...o.o.o.oo.oo.o.o..oo....oo..o..ooooo.o..o..o.o.....oo.o..oo..ooooo.ooooo.o....o...o......oooo. [出力例] 527 |
■参照サイト
AtCoder Regular Contest 040