結果
| 問題 |
No.2042 RGB Caps
|
| コンテスト | |
| ユーザー |
vjudge1
|
| 提出日時 | 2025-11-05 16:01:18 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 28 ms / 2,000 ms |
| コード長 | 1,506 bytes |
| コンパイル時間 | 3,215 ms |
| コンパイル使用メモリ | 284,328 KB |
| 実行使用メモリ | 7,716 KB |
| 最終ジャッジ日時 | 2025-11-05 16:01:23 |
| 合計ジャッジ時間 | 4,934 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 16 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail>
void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
#define dbg(...) cerr << "(" << #__VA_ARGS__ << ")", dbg_out(__VA_ARGS__)
#define int long long
const int MOD = 1e9 + 7;
const int INF = LLONG_MAX >> 1;
void solve() {
int n, k; cin >> n >> k;
pair<int, int> a[k];
for (int i = 0; i < k; i++) {
int x; cin >> x;
char c; cin >> c;
int y;
if (c == 'R') y = 0;
if (c == 'G') y = 1;
if (c == 'B') y = 2;
a[i] = {x, y};
}
sort(a, a + k);
vector<int> ans(n);
for (int i = 0; i < n; i++) {
ans[i] = i % 3;
}
for (int i = 0; i < k; i++) {
auto &[x, y] = a[i];
int k = (x - 1) / 3 * 3, ind = -1;
bool ok = false;
for (int l = k; l < min(k + 3, n); l++) {
if (ans[l] == y) {
ind = l;
ok = true;
break;
}
}
if (!ok) {
ans[x - 1] = y;
} else if (x - 1 < ind) {
swap(ans[x - 1], ans[ind]);
}
}
for (int i = 0; i < n; i++) {
if (ans[i] == 0) cout << 'R';
if (ans[i] == 1) cout << 'G';
if (ans[i] == 2) cout << 'B';
}
cout << '\n';
}
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int tc = 1;
// cin >> tc;
while (tc--) solve();
}
vjudge1