結果
問題 | No.1328 alligachi-problem |
ユーザー | 沙耶花 |
提出日時 | 2020-12-20 12:44:00 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,998 bytes |
コンパイル時間 | 2,970 ms |
コンパイル使用メモリ | 234,500 KB |
実行使用メモリ | 28,800 KB |
最終ジャッジ日時 | 2024-09-21 11:43:16 |
合計ジャッジ時間 | 11,999 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
10,624 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 3 ms
5,376 KB |
testcase_05 | AC | 3 ms
5,376 KB |
testcase_06 | AC | 3 ms
5,376 KB |
testcase_07 | AC | 4 ms
5,376 KB |
testcase_08 | AC | 3 ms
5,376 KB |
testcase_09 | AC | 154 ms
24,620 KB |
testcase_10 | AC | 87 ms
5,504 KB |
testcase_11 | AC | 157 ms
24,600 KB |
testcase_12 | AC | 152 ms
24,492 KB |
testcase_13 | AC | 155 ms
24,620 KB |
testcase_14 | AC | 155 ms
24,628 KB |
testcase_15 | AC | 87 ms
5,632 KB |
testcase_16 | AC | 152 ms
24,620 KB |
testcase_17 | AC | 153 ms
24,616 KB |
testcase_18 | AC | 153 ms
24,496 KB |
testcase_19 | AC | 154 ms
24,492 KB |
testcase_20 | AC | 153 ms
24,492 KB |
testcase_21 | AC | 152 ms
24,736 KB |
testcase_22 | AC | 153 ms
24,628 KB |
testcase_23 | AC | 87 ms
5,504 KB |
testcase_24 | TLE | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
ソースコード
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf 1000000000000000000 struct Ball{ char color,ncolor; int ncnt; int ind; }; deque<Ball> red,blue; deque<Ball> ret; map<char,int> mp; void NG(){ cout<<"No"<<endl; exit(0); } void OK(){ cout<<"Yes"<<endl; rep(i,ret.size()){ if(i!=0)printf(" "); printf("%d",ret[i].ind+1); } cout<<endl; exit(0); } void solve(){ if(red.size()==0&&blue.size()==0)OK(); if(red.size()!=0){ if(mp[red.front().ncolor]>red.front().ncnt)return; } if(blue.size()!=0){ if(mp[blue.front().ncolor]>blue.front().ncnt)return; } if(red.size()==0){ if(mp[blue.front().ncolor]==blue.front().ncnt){ mp[blue.front().color]++; ret.push_back(blue.front()); blue.pop_front(); solve(); blue.push_front(ret.back()); ret.pop_back(); mp[blue.front().color]--; } } else if(blue.size()==0){ if(mp[red.front().ncolor]==red.front().ncnt){ mp[red.front().color]++; ret.push_back(red.front()); red.pop_front(); solve(); red.push_front(ret.back()); ret.pop_back(); mp[red.front().color]--; } } else{ bool f0 = (mp[red.front().ncolor]==red.front().ncnt); bool f1 = (mp[blue.front().ncolor]==blue.front().ncnt); if(!f0&&!f1)return; if(f0&&!f1){ mp[red.front().color]++; ret.push_back(red.front()); red.pop_front(); solve(); red.push_front(ret.back()); ret.pop_back(); mp[red.front().color]--; } else if(!f0){ mp[blue.front().color]++; ret.push_back(blue.front()); blue.pop_front(); solve(); blue.push_front(ret.back()); ret.pop_back(); mp[blue.front().color]--; } else{ mp[blue.front().color]++; ret.push_back(blue.front()); blue.pop_front(); solve(); blue.push_front(ret.back()); ret.pop_back(); mp[blue.front().color]--; mp[red.front().color]++; ret.push_back(red.front()); red.pop_front(); solve(); red.push_front(ret.back()); ret.pop_back(); mp[red.front().color]--; } } } int main(){ int N; cin>>N; vector<int> Y(N); vector<char> C(N),X(N); rep(i,N){ cin>>C[i]>>X[i]>>Y[i]; } deque<int> B,R; rep(i,N){ if(C[i]=='B')B.push_back(-1); else R.push_back(-1); } rep(i,N){ if(C[i]==X[i]){ int t = Y[i]; if(C[i]=='R')swap(B,R); if(t>=B.size())NG(); if(B[t]!=-1)NG(); B[t] = i; if(C[i]=='R')swap(B,R); } } vector<pair<int,int>> pB,pR; rep(i,N){ if(C[i]==X[i])continue; if(C[i]=='B')pB.emplace_back(Y[i],i); else pR.emplace_back(Y[i],i); } sort(pB.begin(),pB.end()); sort(pR.begin(),pR.end()); int now = 0; rep(i,pB.size()){ while(B[now]!=-1)now++; B[now] = pB[i].second; } now = 0; rep(i,pR.size()){ while(R[now]!=-1)now++; R[now] = pR[i].second; } rep(i,B.size()){ blue.push_back({'B',X[B[i]],Y[B[i]],B[i]}); } rep(i,R.size()){ red.push_back({'R',X[R[i]],Y[R[i]],R[i]}); } // blue = B,red = R; solve(); NG(); return 0; }