結果
問題 | No.572 妖精の演奏 |
ユーザー | imulan |
提出日時 | 2017-10-07 00:35:13 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 80 ms / 2,000 ms |
コード長 | 1,459 bytes |
コンパイル時間 | 1,457 ms |
コンパイル使用メモリ | 166,560 KB |
実行使用メモリ | 4,384 KB |
最終ジャッジ日時 | 2023-08-10 18:26:35 |
合計ジャッジ時間 | 2,978 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge11 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 5 ms
4,380 KB |
testcase_01 | AC | 8 ms
4,380 KB |
testcase_02 | AC | 8 ms
4,380 KB |
testcase_03 | AC | 8 ms
4,376 KB |
testcase_04 | AC | 3 ms
4,380 KB |
testcase_05 | AC | 9 ms
4,380 KB |
testcase_06 | AC | 12 ms
4,380 KB |
testcase_07 | AC | 24 ms
4,376 KB |
testcase_08 | AC | 19 ms
4,380 KB |
testcase_09 | AC | 30 ms
4,380 KB |
testcase_10 | AC | 48 ms
4,376 KB |
testcase_11 | AC | 48 ms
4,380 KB |
testcase_12 | AC | 48 ms
4,376 KB |
testcase_13 | AC | 48 ms
4,380 KB |
testcase_14 | AC | 80 ms
4,380 KB |
testcase_15 | AC | 48 ms
4,376 KB |
testcase_16 | AC | 79 ms
4,384 KB |
testcase_17 | AC | 47 ms
4,380 KB |
testcase_18 | AC | 11 ms
4,384 KB |
testcase_19 | AC | 2 ms
4,376 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i)) #define all(x) (x).begin(),(x).end() #define pb push_back #define fi first #define se second #define dbg(x) cout<<#x" = "<<((x))<<endl template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;} template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;} const ll INF = LLONG_MAX/4; ll n; int m; int a[30][30]; ll dp1[30][30][31]; ll f(int from, int to, int step) { if(dp1[from][to][step]>=0) return dp1[from][to][step]; if(step==0) { if(from==to) return 0; return -INF; } ll ret = 0; rep(i,m) ret = max(ret, f(i,to,step-1)+a[from][i]); return dp1[from][to][step] = ret; } ll dp2[30][62]; ll g(int s, int elim) { if(dp2[s][elim]>=0) return dp2[s][elim]; ll rem = n-elim; if(rem<0) return -INF; ll ret = 0; for(int i=1; i<=30; ++i) { if(rem%i==0) ret = max(ret,(rem/i)*f(s,s,i)); } return dp2[s][elim] = ret; } int main() { cin >>n >>m; --n; rep(i,m)rep(j,m) cin >>a[i][j]; memset(dp1,-1,sizeof(dp1)); memset(dp2,-1,sizeof(dp2)); ll ans = 0; rep(i,m)rep(j,m)rep(k,m)rep(ii,31)rep(jj,31) { ans = max(ans, f(i,k,ii) + g(k,ii+jj) + f(k,j,jj)); } cout << ans << endl; return 0; }