結果
問題 | No.1328 alligachi-problem |
ユーザー | outline |
提出日時 | 2020-12-25 05:32:00 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 105 ms / 2,000 ms |
コード長 | 2,577 bytes |
コンパイル時間 | 1,397 ms |
コンパイル使用メモリ | 135,576 KB |
実行使用メモリ | 30,820 KB |
最終ジャッジ日時 | 2023-10-21 18:29:19 |
合計ジャッジ時間 | 8,515 ms |
ジャッジサーバーID (参考情報) |
judge9 / judge10 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 10 ms
23,252 KB |
testcase_01 | AC | 10 ms
23,252 KB |
testcase_02 | AC | 10 ms
23,256 KB |
testcase_03 | AC | 10 ms
23,252 KB |
testcase_04 | AC | 11 ms
23,336 KB |
testcase_05 | AC | 11 ms
23,356 KB |
testcase_06 | AC | 10 ms
23,324 KB |
testcase_07 | AC | 11 ms
23,364 KB |
testcase_08 | AC | 10 ms
23,280 KB |
testcase_09 | AC | 103 ms
29,780 KB |
testcase_10 | AC | 78 ms
29,232 KB |
testcase_11 | AC | 102 ms
29,792 KB |
testcase_12 | AC | 102 ms
29,792 KB |
testcase_13 | AC | 104 ms
29,800 KB |
testcase_14 | AC | 105 ms
29,796 KB |
testcase_15 | AC | 78 ms
29,232 KB |
testcase_16 | AC | 103 ms
29,788 KB |
testcase_17 | AC | 101 ms
29,784 KB |
testcase_18 | AC | 104 ms
29,788 KB |
testcase_19 | AC | 101 ms
29,788 KB |
testcase_20 | AC | 103 ms
29,796 KB |
testcase_21 | AC | 101 ms
29,800 KB |
testcase_22 | AC | 101 ms
29,788 KB |
testcase_23 | AC | 77 ms
29,232 KB |
testcase_24 | AC | 85 ms
30,820 KB |
testcase_25 | AC | 87 ms
30,808 KB |
testcase_26 | AC | 71 ms
28,088 KB |
testcase_27 | AC | 73 ms
28,088 KB |
ソースコード
#include <iostream> #include <vector> #include <algorithm> #include <cmath> #include <queue> #include <string> #include <map> #include <set> #include <stack> #include <tuple> #include <deque> #include <array> #include <numeric> #include <bitset> #include <iomanip> #include <cassert> #include <chrono> #include <random> #include <limits> #include <iterator> #include <functional> #include <sstream> #include <fstream> #include <complex> #include <cstring> #include <unordered_map> using namespace std; using ll = long long; using P = pair<int, int>; constexpr int INF = 1001001001; constexpr int mod = 1000000007; // constexpr int mod = 998244353; template<class T> inline bool chmax(T& x, T y){ if(x < y){ x = y; return true; } return false; } template<class T> inline bool chmin(T& x, T y){ if(x > y){ x = y; return true; } return false; } // dat[C][X][Y] = i vector<int> dat[2][2][200005]; // cnt[X][Y] = \sum dat[C][X][Y] int cnt[2][200005]; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int N; cin >> N; for(int i = 0; i < N; ++i){ char C, X; int Y; cin >> C >> X >> Y; dat[C == 'B'][X == 'B'][Y].emplace_back(i); } for(int i = 0; i < 2; ++i){ for(int j = 0; j < 2; ++j){ for(int k = 0; k < N; ++k){ cnt[j][k] += dat[i][j][k].size(); } } } vector<int> A, color_cnt(2); bool update = true; while(update){ update = false; for(int i = 0; i < 2; ++i){ // 入れようとしている色 (C) int& ci = color_cnt[i]; // 現在の C の個数 for(int j = 0; j < 2; ++j){ // 制約を与える色 (X) int cj = color_cnt[j]; // 現在の X の個数 if(!dat[i][j][cj].size()) continue; // C == X のとき、制約 (X, Y) が自分自身しかない // C != X のとき、制約 (C, Y) であるものがない if((i == j && cnt[j][cj] == 1) || (i != j && cnt[i][ci] == 0)){ A.emplace_back(dat[i][j][cj].back()); dat[i][j][cj].pop_back(); cnt[j][cj] -= 1; ci += 1; update = true; } } } } if(A.size() < N) cout << "No\n"; else{ cout << "Yes\n"; for(int i = 0; i < N; ++i){ cout << A[i] + 1; cout << ((i == N - 1) ? '\n' : ' '); } } return 0; }