結果
問題 | No.1780 [Cherry Anniversary] 真冬に咲く26の櫻の木 |
ユーザー |
![]() |
提出日時 | 2021-12-09 00:29:07 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 272 ms / 2,000 ms |
コード長 | 2,392 bytes |
コンパイル時間 | 2,404 ms |
コンパイル使用メモリ | 209,268 KB |
実行使用メモリ | 19,072 KB |
最終ジャッジ日時 | 2024-07-16 11:27:44 |
合計ジャッジ時間 | 7,884 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 9 ms
9,856 KB |
testcase_01 | AC | 9 ms
9,728 KB |
testcase_02 | AC | 21 ms
9,728 KB |
testcase_03 | AC | 34 ms
9,728 KB |
testcase_04 | AC | 25 ms
9,856 KB |
testcase_05 | AC | 25 ms
9,984 KB |
testcase_06 | AC | 23 ms
9,856 KB |
testcase_07 | AC | 26 ms
9,728 KB |
testcase_08 | AC | 25 ms
9,728 KB |
testcase_09 | AC | 25 ms
9,856 KB |
testcase_10 | AC | 23 ms
9,728 KB |
testcase_11 | AC | 24 ms
9,856 KB |
testcase_12 | AC | 24 ms
9,728 KB |
testcase_13 | AC | 24 ms
9,984 KB |
testcase_14 | AC | 83 ms
11,136 KB |
testcase_15 | AC | 214 ms
16,640 KB |
testcase_16 | AC | 211 ms
16,640 KB |
testcase_17 | AC | 69 ms
10,496 KB |
testcase_18 | AC | 146 ms
13,952 KB |
testcase_19 | AC | 77 ms
10,880 KB |
testcase_20 | AC | 167 ms
14,592 KB |
testcase_21 | AC | 259 ms
18,560 KB |
testcase_22 | AC | 259 ms
18,688 KB |
testcase_23 | AC | 97 ms
11,648 KB |
testcase_24 | AC | 272 ms
19,072 KB |
testcase_25 | AC | 93 ms
11,520 KB |
testcase_26 | AC | 80 ms
11,008 KB |
testcase_27 | AC | 150 ms
14,080 KB |
testcase_28 | AC | 68 ms
10,496 KB |
testcase_29 | AC | 61 ms
10,240 KB |
testcase_30 | AC | 249 ms
18,048 KB |
testcase_31 | AC | 53 ms
9,984 KB |
testcase_32 | AC | 60 ms
10,240 KB |
testcase_33 | AC | 134 ms
13,568 KB |
testcase_34 | AC | 8 ms
10,692 KB |
testcase_35 | AC | 49 ms
10,312 KB |
testcase_36 | AC | 8 ms
9,796 KB |
testcase_37 | AC | 49 ms
10,952 KB |
testcase_38 | AC | 51 ms
12,836 KB |
testcase_39 | AC | 51 ms
13,156 KB |
testcase_40 | AC | 51 ms
13,060 KB |
testcase_41 | AC | 51 ms
12,628 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef signed long long ll; #define _P(...) (void)printf(__VA_ARGS__) #define FOR(x,to) for(x=0;x<(to);x++) #define FORR(x,arr) for(auto& x:arr) #define FORR2(x,y,arr) for(auto& [x,y]:arr) #define ALL(a) (a.begin()),(a.end()) #define ZERO(a) memset(a,0,sizeof(a)) #define MINUS(a) memset(a,0xff,sizeof(a)) template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;} template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;} //------------------------------------------------------- int C[26],K[26]; int N; string S[202020]; ll A[202020],B[202020],E[202020]; ll dp[16][16][31]; ll ret[26][16]; void solve() { int i,j,k,l,r,x,y; string s; FOR(i,26) { cin>>C[i]; C[i]--; } FOR(i,26) { cin>>K[i]; } cin>>N; FOR(i,N) { cin>>S[i]>>A[i]>>B[i]>>E[i]; FORR(c,S[i]) c-='A'; A[i]--; B[i]--; } FOR(i,26) { FOR(x,16) FOR(y,16) dp[x][y][0]=-1LL<<55; FOR(j,N) { if(count(ALL(S[j]),i)) { chmax(dp[A[j]][B[j]][0],E[j]); chmax(dp[B[j]][A[j]][0],E[j]); } } FOR(j,29) { FOR(x,16) FOR(y,16) dp[x][y][j+1]=-1LL<<55;; FOR(x,16) FOR(y,16) FOR(r,16) dp[x][r][j+1]=max(dp[x][r][j+1],dp[x][y][j]+dp[y][r][j]); } FOR(x,16) ret[i][x]=-1LL<<55; for(k=max(0,K[i]-26);k<=K[i];k++) { ll cur[16][16]; FOR(x,16) FOR(y,16) cur[x][y]=(x==y)?0:-1LL<<55; FOR(j,29) if(k&(1<<j)) { ll to[16][16]; FOR(x,16) FOR(y,16) to[x][y]=-1LL<<55; FOR(x,16) FOR(y,16) FOR(r,16) to[x][r]=max(to[x][r],cur[x][y]+dp[y][r][j]); swap(cur,to); } FOR(x,16) ret[i][x]=max(ret[i][x],cur[C[i]][x]); } for(k=0;k<=min(26,K[i]);k++) { ll cur[16][16]; FOR(x,16) FOR(y,16) cur[x][y]=(x==y)?0:-1LL<<55; FOR(j,29) if(k&(1<<j)) { ll to[16][16]; FOR(x,16) FOR(y,16) to[x][y]=-1LL<<55; FOR(x,16) FOR(y,16) FOR(r,16) to[x][r]=max(to[x][r],cur[x][y]+dp[y][r][j]); swap(cur,to); } FOR(x,16) ret[i][x]=max(ret[i][x],cur[C[i]][x]); } } ll ma=-1LL<<55; FOR(x,16) { ll sum=0; FOR(i,26) sum+=ret[i][x]; ma=max(ma,sum); } if(ma<-1LL<<54) { cout<<"Impossible"<<endl; } else { cout<<ma<<endl; } } int main(int argc,char** argv){ string s;int i; if(argc==1) ios::sync_with_stdio(false), cin.tie(0); FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin); cout.tie(0); solve(); return 0; }