結果
問題 | No.1780 [Cherry Anniversary] 真冬に咲く26の櫻の木 |
ユーザー | 👑 kmjp |
提出日時 | 2021-12-09 00:29:07 |
言語 | C++17 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 272 ms / 2,000 ms |
コード長 | 2,392 bytes |
コンパイル時間 | 2,503 ms |
コンパイル使用メモリ | 205,436 KB |
実行使用メモリ | 19,104 KB |
最終ジャッジ日時 | 2023-09-23 11:52:45 |
合計ジャッジ時間 | 8,009 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 11 ms
12,728 KB |
testcase_01 | AC | 11 ms
10,464 KB |
testcase_02 | AC | 23 ms
12,592 KB |
testcase_03 | AC | 35 ms
12,860 KB |
testcase_04 | AC | 27 ms
12,672 KB |
testcase_05 | AC | 26 ms
12,540 KB |
testcase_06 | AC | 25 ms
12,600 KB |
testcase_07 | AC | 27 ms
12,652 KB |
testcase_08 | AC | 28 ms
12,540 KB |
testcase_09 | AC | 26 ms
12,732 KB |
testcase_10 | AC | 25 ms
12,536 KB |
testcase_11 | AC | 26 ms
12,520 KB |
testcase_12 | AC | 24 ms
12,536 KB |
testcase_13 | AC | 25 ms
12,804 KB |
testcase_14 | AC | 85 ms
13,688 KB |
testcase_15 | AC | 214 ms
17,664 KB |
testcase_16 | AC | 211 ms
17,400 KB |
testcase_17 | AC | 71 ms
13,244 KB |
testcase_18 | AC | 147 ms
15,856 KB |
testcase_19 | AC | 80 ms
13,580 KB |
testcase_20 | AC | 171 ms
16,224 KB |
testcase_21 | AC | 258 ms
18,732 KB |
testcase_22 | AC | 263 ms
18,956 KB |
testcase_23 | AC | 101 ms
14,212 KB |
testcase_24 | AC | 272 ms
19,104 KB |
testcase_25 | AC | 95 ms
13,976 KB |
testcase_26 | AC | 82 ms
13,656 KB |
testcase_27 | AC | 152 ms
15,788 KB |
testcase_28 | AC | 70 ms
13,132 KB |
testcase_29 | AC | 63 ms
12,852 KB |
testcase_30 | AC | 256 ms
18,496 KB |
testcase_31 | AC | 53 ms
12,628 KB |
testcase_32 | AC | 62 ms
13,088 KB |
testcase_33 | AC | 137 ms
15,284 KB |
testcase_34 | AC | 10 ms
10,476 KB |
testcase_35 | AC | 51 ms
10,528 KB |
testcase_36 | AC | 11 ms
10,480 KB |
testcase_37 | AC | 51 ms
10,612 KB |
testcase_38 | AC | 53 ms
12,620 KB |
testcase_39 | AC | 52 ms
12,744 KB |
testcase_40 | AC | 53 ms
12,544 KB |
testcase_41 | AC | 53 ms
12,520 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; }