結果
問題 | No.1328 alligachi-problem |
ユーザー | 沙耶花 |
提出日時 | 2020-12-20 12:39:30 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,840 bytes |
コンパイル時間 | 2,690 ms |
コンパイル使用メモリ | 233,728 KB |
実行使用メモリ | 30,368 KB |
最終ジャッジ日時 | 2024-09-21 11:41:55 |
合計ジャッジ時間 | 10,933 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
12,192 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 1 ms
5,376 KB |
testcase_03 | AC | 1 ms
5,376 KB |
testcase_04 | AC | 3 ms
5,376 KB |
testcase_05 | AC | 3 ms
5,376 KB |
testcase_06 | AC | 2 ms
5,376 KB |
testcase_07 | AC | 3 ms
5,376 KB |
testcase_08 | AC | 2 ms
5,376 KB |
testcase_09 | AC | 148 ms
24,748 KB |
testcase_10 | AC | 83 ms
5,632 KB |
testcase_11 | AC | 150 ms
24,728 KB |
testcase_12 | AC | 138 ms
24,616 KB |
testcase_13 | AC | 155 ms
24,488 KB |
testcase_14 | AC | 150 ms
24,500 KB |
testcase_15 | AC | 84 ms
5,632 KB |
testcase_16 | AC | 147 ms
24,496 KB |
testcase_17 | AC | 147 ms
24,624 KB |
testcase_18 | AC | 146 ms
24,496 KB |
testcase_19 | AC | 146 ms
24,624 KB |
testcase_20 | AC | 147 ms
24,488 KB |
testcase_21 | AC | 141 ms
24,736 KB |
testcase_22 | AC | 143 ms
24,628 KB |
testcase_23 | AC | 82 ms
6,940 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[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[red.front().color]++; ret.push_back(red.front()); red.pop_front(); solve(); red.push_front(ret.back()); ret.pop_back(); mp[red.front().color]--; 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]--; } } } 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; }