結果
問題 | No.1328 alligachi-problem |
ユーザー | tnakao0123 |
提出日時 | 2020-12-25 23:11:03 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 82 ms / 2,000 ms |
コード長 | 2,022 bytes |
コンパイル時間 | 1,138 ms |
コンパイル使用メモリ | 103,976 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-22 16:41:25 |
合計ジャッジ時間 | 6,508 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 25 |
ソースコード
/* -*- coding: utf-8 -*- * * 1328.cc: No.1328 alligachi-problem - yukicoder */ #include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<iostream> #include<string> #include<vector> #include<map> #include<set> #include<stack> #include<list> #include<queue> #include<deque> #include<algorithm> #include<numeric> #include<utility> #include<complex> #include<functional> using namespace std; /* constant */ const int MAX_N = 200000; const char ccs[] = "RB"; enum { R = 0, B = 1 }; /* typedef */ typedef pair<int,int> pii; typedef vector<pii> vpii; /* global variables */ vpii wcs[2][2]; int cis[2][2], as[MAX_N]; /* subroutines */ inline int c2i(char c) { return (c == 'R') ? R : (c == 'B') ? B : -1; } inline int wcsize(int c, int x, int y) { vpii &wc = wcs[c][x]; int k = 0; for (int i = cis[c][x]; k < 2 && i < wc.size() && wc[i].first == y; i++, k++); return k; } inline int wcget(int c, int x) { return wcs[c][x][cis[c][x]++].second; } /* main */ int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) { char s[8], t[8]; int y; scanf("%s%s%d", s, t, &y); int c = c2i(s[0]), x = c2i(t[0]); wcs[c][x].push_back(pii(y, i)); } for (int i = 0; i < 2; i++) for (int j = 0; j < 2; j++) sort(wcs[i][j].begin(), wcs[i][j].end()); for (int i = 0, rn = 0, bn = 0; i < n; i++) { if (wcsize(R, R, rn) == 1 && wcsize(B, R, rn) == 0) as[i] = wcget(R, R), rn++; else if (wcsize(B, B, bn) == 1 && wcsize(R, B, bn) == 0) as[i] = wcget(B, B), bn++; else if (wcsize(R, B, bn) > 0 && wcsize(R, R, rn) == 0 && wcsize(B, R, rn) == 0) as[i] = wcget(R, B), rn++; else if (wcsize(B, R, rn) > 0 && wcsize(R, B, bn) == 0 && wcsize(B, B, bn) == 0) as[i] = wcget(B, R), bn++; else { puts("No"); return 0; } //printf("as[%d]=%d\n", i, as[i]); } puts("Yes"); for (int i = 0; i < n; i++) printf("%d%c", as[i] + 1, (i + 1 < n) ? ' ' : '\n'); return 0; }