結果
問題 |
No.1328 alligachi-problem
|
ユーザー |
![]() |
提出日時 | 2021-01-08 23:36:48 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,589 bytes |
コンパイル時間 | 3,164 ms |
コンパイル使用メモリ | 205,624 KB |
最終ジャッジ日時 | 2025-01-17 14:44:43 |
ジャッジサーバーID (参考情報) |
judge4 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 22 TLE * 3 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; #define v(t) vector<t> #define p(t) pair<t, t> #define p2(t, s) pair<t, s> #define vp(t) v(p(t)) #define rep(i, n) for (int i=0,i##_len=((int)(n)); i<i##_len; ++i) #define rep2(i, a, n) for (int i=((int)(a)),i##_len=((int)(n)); i<=i##_len; ++i) #define repr(i, n) for (int i=((int)(n)-1); i>=0; --i) #define rep2r(i, a, n) for (int i=((int)(n)),i##_len=((int)(a)); i>=i##_len; --i) #define repi(itr, c) for (__typeof((c).begin()) itr=(c).begin(); itr!=(c).end(); ++itr) #define repir(itr, c) for (__typeof((c).rbegin()) itr=(c).rbegin(); itr!=(c).rend(); ++itr) #define sz(x) ((int)(x).size()) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define SORT(v, n) sort(v, v+n); #define VSORT(v) sort(v.begin(), v.end()); #define RSORT(x) sort(rall(x)); #define pb push_back #define eb emplace_back #define INF (1e9) #define LINF (1e18) #define PI (acos(-1)) #define EPS (1e-7) #define DEPS (1e-10) // 解説読んで提出したい(やりかけ) int n, rnum, bnum; v(int) ans, cnt; v(v(int)) rb; v(p(p(int))) xy; bool dfs(int r, int b) { if (r+b == n) return true; if (r < rnum) { int rid = rb[0][r]; if (cnt[0] == xy[rid].first.first) { ans[r+b] = xy[rid].second.second + 1; cnt[xy[rid].first.second]++; if (dfs(r+1, b)) return true; cnt[xy[rid].first.second]--; ans[r+b] = 0; } } if (b < bnum) { int bid = rb[1][b]; if (cnt[1] == xy[bid].first.first) { ans[r+b] = xy[bid].second.second + 1; cnt[(1+xy[bid].first.second)%2]++; if (dfs(r, b+1)) return true; cnt[(1+xy[bid].first.second)%2]--; ans[r+b] = 0; } } return false; } int main(){ cin >> n; xy = v(p(p(int)))(n); rep(i, n) { char ci, xi; cin >> ci >> xi >> xy[i].first.first; xy[i].first.second = ((ci==xi)?0:-1); xy[i].second.first = ((xi=='R')?0:1); xy[i].second.second = i; } VSORT(xy); rep(i, n) xy[i].first.second *= -1; rb = v(v(int))(2); rep(i, n) rb[xy[i].second.first].pb(i); rnum = sz(rb[0]); bnum = sz(rb[1]); ans = v(int)(n); cnt = v(int)(2); if (dfs(0, 0)) { cout << "Yes" << endl; rep(i, n) printf("%d%c", ans[i], (i<n-1?' ':'\n')); } else cout << "No" << endl; return 0; }