結果

問題 No.572 妖精の演奏
ユーザー parukiparuki
提出日時 2017-10-11 21:17:25
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 12 ms / 2,000 ms
コード長 1,741 bytes
コンパイル時間 1,614 ms
コンパイル使用メモリ 169,392 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-28 16:13:54
合計ジャッジ時間 2,347 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 3 ms
6,944 KB
testcase_06 AC 4 ms
6,944 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 3 ms
6,940 KB
testcase_09 AC 4 ms
6,940 KB
testcase_10 AC 12 ms
6,940 KB
testcase_11 AC 12 ms
6,944 KB
testcase_12 AC 12 ms
6,940 KB
testcase_13 AC 12 ms
6,940 KB
testcase_14 AC 12 ms
6,944 KB
testcase_15 AC 12 ms
6,940 KB
testcase_16 AC 12 ms
6,944 KB
testcase_17 AC 12 ms
6,944 KB
testcase_18 AC 2 ms
6,940 KB
testcase_19 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

int NG = INT_MIN / 3;
int M, score[31][31], dp[31][31][31], dpdp[31][31];// 最初がiでj個で最大(終わりは不明)

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);

    ll N;
    cin >> N >> M;
    rep(i, M) rep(j, M)cin >> score[i][j];

    rep(i, M + 1)rep(j, M + 1)rep(k, M + 1)dp[i][j][k] = NG;
    rep(i, M + 1)dp[i][0][i] = 0;

    rep(fi, M + 1)rep(i, M)rep(j, M + 1) if(dp[fi][i][j]>NG){
        rep(nj, M) {
            smax(dp[fi][i + 1][nj], dp[fi][i][j] + score[j][nj]);
        }
    }

    rep(fi, M + 1)rep(num, M + 1) {
        dpdp[fi][num] = NG;
        rep(las, M + 1)smax(dpdp[fi][num], dp[fi][num][las]);
    }

    ll ans = 0;
    if (N <= M) {
        rep(i, M)smax(ans, (ll)dp[M][N][i]);
        cout << ans << endl;
        return 0;
    }

    // M => i => j
    rep(i, M)rep(j, M) {
        FOR(a, 1, M + 1) if (dp[M][a][i] > NG){
            FOR(b, 1, M + 1) if (dp[i][b][j] > NG) {
                ll q = (N - a) / b;
                if (q == 0)continue;
                ll r = (N - a) % b;

                smax(ans, dp[M][a][i] + dp[i][b][j] + dp[j][b][j] * (q-1) + dpdp[j][r]);
            }
        }
    }
    cout << ans << endl;
}
0