AtCoder Regular Contest 001

Submission #1589881

Source codeソースコード

#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v)) os<<*i<<(i==end(v)-1?"":"\n"); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
    is>>p.first>>p.second; return is; }
template<class T>bool chmax(T &a,const T &b) {if(a<b) {a=b;return 1;} return 0;}
template<class T>bool chmin(T &a,const T &b) {if(b<a) {a=b;return 1;} return 0;}
//------------------------------------------------------------------------------
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
        #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

bool x[8],y[8];
bool d1[20],d2[20];
signed main() {
    vector<string> s(8);
    cin>>s;
    REP(i,8) REP(j,8) if(s[i][j]=='Q') {
        if(y[i]||x[j]||d1[i+j]||d2[7-j+i]) {
            cout<<"No Answer"<<endl;
            return 0;
        }
        y[i]=x[j]=d1[i+j]=d2[i+7-j]=1;
    }
    vector<int> X;
    REP(j,8) if(!x[j]) X.push_back(j);

    REP(a,8) {
        if(y[a]||d1[X[0]+a]||d2[7-X[0]+a]) continue;
        y[a]=d1[X[0]+a]=d2[7-X[0]+a]=1;
        REP(b,8) {
            if(y[b]||d1[X[1]+b]||d2[7-X[1]+b]) continue;
            y[b]=d1[X[1]+b]=d2[7-X[1]+b]=1;
            REP(c,8) {
                if(y[c]||d1[X[2]+c]||d2[7-X[2]+c]) continue;
                y[c]=d1[X[2]+c]=d2[7-X[2]+c]=1;
                REP(d,8) {
                    if(y[d]||d1[X[3]+d]||d2[7-X[3]+d]) continue;
                    y[d]=d1[X[3]+d]=d2[7-X[3]+d]=1;
                    REP(e,8) {
                        if(y[e]||d1[X[4]+e]||d2[7-X[4]+e]) continue;
                        y[e]=d1[X[4]+e]=d2[7-X[4]+e]=1;

                        s[a][X[0]]=s[b][X[1]]=s[c][X[2]]=s[d][X[3]]=s[e][X[4]]='Q';
                        REP(i,8) cout<<s[i]<<endl;
                        return 0;

                        y[e]=d1[X[4]+e]=d2[7-X[4]+e]=0;
                    }
                    y[d]=d1[X[3]+d]=d2[7-X[3]+d]=0;
                }
                y[c]=d1[X[2]+c]=d2[7-X[2]+c]=0;
            }
            y[b]=d1[X[1]+b]=d2[7-X[1]+b]=0;
        }
        y[a]=d1[X[0]+a]=d2[7-X[0]+a]=0;
    }
    cout<<"No Answer"<<endl;
    return 0;
}

Submission

Task問題 C - パズルのお手伝い
User nameユーザ名 あるごん
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 AC
Score得点 100
Source lengthソースコード長 3238 Byte
File nameファイル名
Exec time実行時間 1 ms
Memory usageメモリ使用量 256 KB

Test case

Set

Set name Score得点 / Max score Cases
All 100 / 100 00_sample1.txt,00_sample2.txt,01_rnd_00.txt,01_rnd_01.txt,01_rnd_02.txt,01_rnd_03.txt,01_rnd_04.txt,01_rnd_05.txt,01_rnd_06.txt,01_rnd_07.txt,01_rnd_08.txt,01_rnd_09.txt,01_rnd_10.txt,01_rnd_11.txt,01_rnd_12.txt,01_rnd_13.txt,01_rnd_14.txt,01_rnd_15.txt,01_rnd_16.txt,01_rnd_17.txt,01_rnd_18.txt,01_rnd_19.txt,01_rnd_20.txt,01_rnd_21.txt,01_rnd_22.txt,01_rnd_23.txt,01_rnd_24.txt,01_rnd_25.txt,01_rnd_26.txt,01_rnd_27.txt,01_rnd_28.txt,01_rnd_29.txt,01_rnd_30.txt,01_rnd_31.txt,01_rnd_32.txt,01_rnd_33.txt,01_rnd_34.txt,01_rnd_35.txt,01_rnd_36.txt,01_rnd_37.txt,01_rnd_38.txt,01_rnd_39.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
00_sample1.txt AC 1 ms 256 KB
00_sample2.txt AC 1 ms 256 KB
01_rnd_00.txt AC 1 ms 256 KB
01_rnd_01.txt AC 1 ms 256 KB
01_rnd_02.txt AC 1 ms 256 KB
01_rnd_03.txt AC 1 ms 256 KB
01_rnd_04.txt AC 1 ms 256 KB
01_rnd_05.txt AC 1 ms 256 KB
01_rnd_06.txt AC 1 ms 256 KB
01_rnd_07.txt AC 1 ms 256 KB
01_rnd_08.txt AC 1 ms 256 KB
01_rnd_09.txt AC 1 ms 256 KB
01_rnd_10.txt AC 1 ms 256 KB
01_rnd_11.txt AC 1 ms 256 KB
01_rnd_12.txt AC 1 ms 256 KB
01_rnd_13.txt AC 1 ms 256 KB
01_rnd_14.txt AC 1 ms 256 KB
01_rnd_15.txt AC 1 ms 256 KB
01_rnd_16.txt AC 1 ms 256 KB
01_rnd_17.txt AC 1 ms 256 KB
01_rnd_18.txt AC 1 ms 256 KB
01_rnd_19.txt AC 1 ms 256 KB
01_rnd_20.txt AC 1 ms 256 KB
01_rnd_21.txt AC 1 ms 256 KB
01_rnd_22.txt AC 1 ms 256 KB
01_rnd_23.txt AC 1 ms 256 KB
01_rnd_24.txt AC 1 ms 256 KB
01_rnd_25.txt AC 1 ms 256 KB
01_rnd_26.txt AC 1 ms 256 KB
01_rnd_27.txt AC 1 ms 256 KB
01_rnd_28.txt AC 1 ms 256 KB
01_rnd_29.txt AC 1 ms 256 KB
01_rnd_30.txt AC 1 ms 256 KB
01_rnd_31.txt AC 1 ms 256 KB
01_rnd_32.txt AC 1 ms 256 KB
01_rnd_33.txt AC 1 ms 256 KB
01_rnd_34.txt AC 1 ms 256 KB
01_rnd_35.txt AC 1 ms 256 KB
01_rnd_36.txt AC 1 ms 256 KB
01_rnd_37.txt AC 1 ms 256 KB
01_rnd_38.txt AC 1 ms 256 KB
01_rnd_39.txt AC 1 ms 256 KB