結果

問題 No.74 貯金箱の退屈
ユーザー codershifth
提出日時 2015-07-31 07:48:34
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 1,774 bytes
コンパイル時間 1,246 ms
コンパイル使用メモリ 162,756 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-17 22:52:42
合計ジャッジ時間 2,377 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 18 WA * 12
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(int (i)=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define RANGE(vec) (vec).begin(),(vec).end()

using namespace std;


class BoredomOfSavingsBox {
public:
    void solve(void) {
            int N;
            cin>>N;
            vector<int> D(N);
            REP(i,N)
                cin>>D[i];
            vector<int> W(N);
            REP(i,N)
                cin>>W[i];

            // O(N^3)
            REP(i, N)
            {
                bool all_ok = false;
                vector<int> w(W);
                int d = D[i];
                int l = (d+i)%N;
                int r = (N*1000-d+i)%N;
                w[i] ^= 1;
                // d による周期は最大 N
                REP(j, N)
                {
                    bool ok = true;
                    REP(i, N)
                        ok &= (w[i]==1);
                    if (ok)
                    {
                        all_ok = true;
                        break;
                    }
                    if (l == r)
                        w[l] ^= 1;
                    else
                    {
                        w[l] ^= 1;
                        w[r] -= 1;
                    }
                    l = (l+d)%N;
                    r = (N*1000-d+r)%N;
                }
                if (all_ok)
                {
                    cout<<"Yes"<<endl;
                    return;
                }
            }
            cout<<"No"<<endl;
            return;
    }
};

#if 1
int main(int argc, char *argv[])
{
        ios::sync_with_stdio(false);
        auto obj = new BoredomOfSavingsBox();
        obj->solve();
        delete obj;
        return 0;
}
#endif
0