結果

問題 No.355 数当てゲーム(2)
ユーザー なおなお
提出日時 2015-07-25 23:04:01
言語 C++11
(gcc 13.3.0)
結果
AC  
実行時間 25 ms / 2,000 ms
コード長 1,311 bytes
コンパイル時間 1,484 ms
コンパイル使用メモリ 159,024 KB
実行使用メモリ 25,472 KB
平均クエリ数 5.52
最終ジャッジ日時 2024-07-16 20:52:29
合計ジャッジ時間 5,385 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 52
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
#define REP(i, n)           for(int(i)=0;(i)<(n);++(i))

bool m[10000];

int main(){
    REP(i,10000){
        int k = i;
        bool f[10], ff;
        REP(j,10) f[j] = false;
        ff = true;
        REP(j,4){
            int l = k % 10;
            if(f[l]){ ff = false; break; }
            f[l] = true;
            k /= 10;
        }
        if(ff) m[i] = true;
    }

    while(1) REP(i,10000){
        if(!m[i]) continue;

        int N[4], t = i; bool f[10];
        REP(j,10) f[j] = false;
        REP(j,4){ int l = t % 10; N[3-j] = l, f[l] = true, t /= 10; }
        REP(j,4) cout << N[j] << " ";
        cout << endl;

        int x = -1, y = -1;
        cin >> x >> y;
        //cerr << "ans = " << x << "," << y << endl;
        if(x == 4 && y == 0){
            //cerr << "answer success" << endl;
            return 0;
        }

        REP(k,10000){
            if(!m[k]) continue;

            int M[4], t = k;
            REP(j,4){ M[3-j] = t % 10; t /= 10; }

            int x1 = 0, y1 = 0;
            REP(i,4){
                if(N[i] == M[i]){ x1++; continue; }
                if(f[M[i]]){ y1++; continue; }
            }
            if(x != x1 || y != y1) m[k] = false;
        }
    }

    return 0;
}

0