結果
| 問題 |
No.2042 RGB Caps
|
| コンテスト | |
| ユーザー |
鴨志田卓
|
| 提出日時 | 2023-02-22 16:07:10 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 47 ms / 2,000 ms |
| コード長 | 999 bytes |
| コンパイル時間 | 1,908 ms |
| コンパイル使用メモリ | 170,256 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-22 17:41:01 |
| 合計ジャッジ時間 | 4,039 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 16 |
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:37:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
37 | auto [x, c] = a[i];
| ^
ソースコード
#include <bits/stdc++.h>
using namespace std;
using pic = pair<int, char>;
const int N = 1e5 + 10;
int n, k;
pic a[N];
char ans[N];
int cnt[256];
char minc() {
for(char c : {'R', 'G', 'B'}) {
bool ok = true;
for(char v : {'R', 'G', 'B'})
if(cnt[c] > cnt[v]) {
ok = false;
break;
}
if(ok) return c;
}
return 'r';
}
int main() {
cin >> n >> k;
for(int i = 1; i <= k; i ++) {
cin >> a[i].first >> a[i].second;
}
for(int i = 1; i <= n; i ++)
ans[i] = 'R';
sort(a + 1, a + k + 1);
for(int i = 1, cur = 1; i <= k; i ++) {
auto [x, c] = a[i];
while(cur < x) ans[cur ++] = minc(), cnt[minc()] ++;
if(cnt[c] < cnt['R'] || cnt[c] < cnt['G'] || cnt[c] < cnt['B'] || (cnt['R'] == cnt['G'] && cnt['G'] == cnt['B']))
ans[cur ++] = c, cnt[c] ++;
else
ans[cur ++] = minc(), cnt[minc()] ++;
}
cout << ans + 1;
}
鴨志田卓