結果

問題 No.572 妖精の演奏
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2017-10-06 23:57:52
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,161 ms / 2,000 ms
コード長 2,608 bytes
コンパイル時間 2,151 ms
コンパイル使用メモリ 167,360 KB
実行使用メモリ 10,648 KB
最終ジャッジ日時 2023-08-10 17:39:14
合計ジャッジ時間 9,680 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
9,972 KB
testcase_01 AC 11 ms
9,976 KB
testcase_02 AC 10 ms
10,176 KB
testcase_03 AC 10 ms
10,024 KB
testcase_04 AC 48 ms
9,460 KB
testcase_05 AC 183 ms
10,632 KB
testcase_06 AC 254 ms
10,376 KB
testcase_07 AC 16 ms
10,492 KB
testcase_08 AC 18 ms
10,380 KB
testcase_09 AC 20 ms
10,500 KB
testcase_10 AC 1,161 ms
10,364 KB
testcase_11 AC 1,129 ms
10,364 KB
testcase_12 AC 1,131 ms
10,564 KB
testcase_13 AC 1,132 ms
10,496 KB
testcase_14 AC 39 ms
10,344 KB
testcase_15 AC 39 ms
10,436 KB
testcase_16 AC 38 ms
10,648 KB
testcase_17 AC 1,129 ms
10,352 KB
testcase_18 AC 13 ms
10,380 KB
testcase_19 AC 7 ms
8,040 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
            ∧_∧  
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     
    /   \     | |     
    /   / ̄ ̄ ̄ ̄/  |  
  __(__ニつ/     _/ .| .|____  
     \/____/ (u ⊃  
---------------------------------------------------------------------------------------------------*/


typedef long long ll;
ll N; int M;
// dp[len][s][t] := max
ll dp[1010][30][30];
ll A[30][30];
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N >> M;
    rep(y, 0, M) rep(x, 0, M) cin >> A[y][x];

    rep(s, 0, M) rep(t, 0, M) dp[2][s][t] = A[s][t];
    rep(le, 2, 1000) rep(s, 0, M) rep(t, 0, M) {
        rep(to, 0, M) dp[le + 1][s][to] = max(dp[le + 1][s][to], dp[le][s][t] + A[t][to]);
    }

    ll ans = 0;
    if (N <= 100) {
        rep(s, 0, M) rep(t, 0, M) ans = max(ans, dp[N][s][t]);
    } else {
        rep(s, 0, M) rep(c, 0, M) rep(t, 0, M) rep(len1, 1, 32) rep(len2, 3, 32) {
            if (len1 == 1 && s != c) continue;
            ll _d = N - len1 + 1;
            int m = _d % (len2 - 1);
            for (int len3 = len2 - 1 - m; len3 < 32; len3 += len2 - 1) {
                if (len3 == 1 && c != t) continue;
                ll d = N - len1 - len3 + 1;
                ll cc = dp[len1][s][c] + dp[len3][c][t];
                //assert(d % (len2 - 1) == 0);
                cc += dp[len2][c][c] * (d / (len2 - 1));
                if (ans < cc) {
                    ans = cc;
                }
            }
        }
    }

    cout << ans << endl;
    

    return;
    string st = "ABCDEFGHIJKL";
    int ss = 0, tt = 0;
    rep(s, 0, M) rep(t, 0, M) if (ans == dp[N][s][t]) {
        ss = s;
        tt = t;
    }
    string res = "";
    res += st[tt];
    while (N) {
        rep(t, 0, M) if (dp[N][ss][tt] == dp[N - 1][ss][t] + A[t][tt]) {
            res = st[t] + res;
            tt = t;
            N--;
            break;
        }
    }
    cout << res << endl;
}
0