結果

問題 No.3235 巡回減算
ユーザー SnowBeenDiding
提出日時 2025-08-15 22:04:14
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 1,216 ms / 10,000 ms
コード長 1,007 bytes
コンパイル時間 5,286 ms
コンパイル使用メモリ 335,004 KB
実行使用メモリ 296,228 KB
最終ジャッジ日時 2025-08-15 22:05:05
合計ジャッジ時間 43,095 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#include <atcoder/all>
#define rep(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
using namespace atcoder;
using namespace std;

typedef long long ll;

vector<int> f(int x) {
    vector<int> ret;
    rep(i, 0, 8) {
        x = (x % 10) * 10000000 + (x / 10);
        ret.push_back(x);
    }
    return ret;
}

void solve() {
    int n;
    cin >> n;
    vector dp(2, vector<char>(100000000));
    dp[0][n] = 1;
    rep(i, 0, 7) {
        int x;
        cin >> x;
        auto xs = f(x);
        rep(j, 0, 100000000) {
            if (dp[0][j] == 0) continue;
            rep(k, 0, 8) {
                if (j >= xs[k]) {
                    dp[1][j - xs[k]] = 1;
                }
            }
        }
        swap(dp[0], dp[1]);
        rep(j, 0, 100000000) dp[1][j] = 0;
    }
    cout << (dp[0][0] ? "Yes" : "No") << endl;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(12);
    int t = 1;
    while (t--) solve();
}
0