結果

問題 No.572 妖精の演奏
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2017-10-06 23:38:20
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,465 bytes
コンパイル時間 1,636 ms
コンパイル使用メモリ 170,440 KB
実行使用メモリ 10,368 KB
最終ジャッジ日時 2024-04-28 11:01:00
合計ジャッジ時間 11,927 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 WA -
権限があれば一括ダウンロードができます

ソースコード

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, 1010) 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, 40) rep(len2, 3, 40) rep(len3, 1, 40) {
            if (len1 == 1 && s != c) continue;
            if (len3 == 1 && c != t) continue;
            ll d = N - len1 - len3 + 1;
            if (d % (len2 - 1) == 0) {
                ll cc = dp[len1][s][c] + dp[len3][c][t];
                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