AtCoder Regular Contest 001

Submission #1589712

Source codeソースコード

#include <algorithm>
#include <numeric>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <complex>
typedef long long ll;

using namespace std;

const int DEFAULT = -9999;

bool is_ok(int q[]) {
  for (int i = 0; i < 7; i++) {
    for (int j = i + 1; j < 8; j++) {
      if (q[i] != DEFAULT) {
        if (q[i] == q[j]) {
          return false;
        }
        if (abs(q[i] - q[j]) == j - i) {
          return false;
        }
      }
    }
  }
  return true;
}

bool put_ok(int q[], int remains) {
  if (remains == 0) {
    if (is_ok(q)) {
      return true;
    } else {
      return false;
    }
  }

  for (int i = 0; i < 8; i++) {
    if (q[i] == DEFAULT) {
      for (int j = 0; j < 8; j++) {
        q[i] = j;
        if (is_ok(q)) {
          if (put_ok(q, remains - 1)) {
            return true;
          }
        }
      }
      q[i] = DEFAULT;
    }
  }
  return false;
}



int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int q[8];
    for (int i = 0; i < 8; i++) {
      q[i] = DEFAULT;
    }

    for (int i = 0; i < 8; i++) {
      string s;
      cin >> s;
      for (int j = 0; j < 8; j++) {
        if (s[j] == 'Q') {
          if (q[i] != DEFAULT) {
            cout << "No Answer" << endl;
            return 0;
          }
          q[i] = j;
        }
      }
    }
    if (!is_ok(q)) {
      cout << "No Answer" << endl;
      return 0;
    }
    if (put_ok(q, 5)) {
      for (int i = 0; i < 8; i++) {
        string s("........");
        s[q[i]] = 'Q';
        cout << s << endl;
      }
      return 0;
    }
    cout << "No Answer" << endl;
    return 0;
}

Submission

Task問題 C - パズルのお手伝い
User nameユーザ名 sinhrks
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 AC
Score得点 100
Source lengthソースコード長 1904 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