結果

問題 No.359 門松行列
ユーザー mayoko_mayoko_
提出日時 2016-04-22 19:33:16
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,017 bytes
コンパイル時間 1,357 ms
コンパイル使用メモリ 113,932 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-15 04:13:46
合計ジャッジ時間 1,610 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
//#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
//#include<list>
#include<queue>
#include<deque>
#include<algorithm>
//#include<numeric>
#include<utility>
#include<complex>
//#include<memory>
#include<functional>
#include<cassert>
#include<set>
#include<stack>
#include<random>

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;

bool isKadomatsu(int a0, int a1, int a2) {
    if (a0 == a1 || a0 == a2 || a1 == a2) return false;
    if (a0 > a1 && a1 < a2) return true;
    if (a0 < a1 && a1 > a2) return true;
    return false;
}

int A[3][3];

bool isOK() {
    for (int i = 0; i < 3; i++) {
        if (!isKadomatsu(A[i][0], A[i][1], A[i][2])) return false;
        if (!isKadomatsu(A[0][i], A[1][i], A[2][i])) return false;
    }
    if (!isKadomatsu(A[0][0], A[1][1], A[2][2])) return false;
    if (!isKadomatsu(A[0][2], A[1][1], A[2][0])) return false;
    return true;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int T;
    cin >> T;
    while (T--) {
        int L;
        cin >> L;
        vi empty;
        for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++) {
            cin >> A[i][j];
            if (A[i][j] == 0) empty.push_back(i*3+j);
        }
        vi vs;
        for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++) {
            if (A[i][j] != 0) {
                if (L-A[i][j] > 0) {
                    vs.push_back(A[i][j]);
                    vs.push_back(L-A[i][j]);
                }
            }
        }
        for (int i = -1; i <= 1; i++) {
            if (L/2+i > 0) vs.push_back(L/2+i);
        }
        vs.push_back(L/2);
        sort(vs.begin(), vs.end());
        vs.erase(unique(vs.begin(), vs.end()), vs.end());
        vector<pii> ps;
        int n = vs.size();
        if (vs[0] > 1) ps.emplace_back(1, vs[0]-1);
        for (int i = 0; i < n; i++) {
            ps.emplace_back(vs[i], vs[i]);
            if (i < n-1) {
                if (vs[i]+1 < vs[i+1]) ps.emplace_back(vs[i]+1, vs[i+1]-1);
            }
        }
        int ans = 0;
        for (pii p : ps) {
//            cout << p.first << "  " << p.second ;
            A[empty[0]/3][empty[0]%3] = p.first;
            A[empty[1]/3][empty[1]%3] = L-p.first;
            if (isOK()) {
//                cout << " OK" << endl;
                ans += p.second-p.first+1;
            } //else cout << " NG" << endl;
        }
        cout << ans << endl;
//        ans = 0;
//        for (int l = 1; l < L; l++) {
//            A[empty[0]/3][empty[0]%3] = l;
//            A[empty[1]/3][empty[1]%3] = L-l;
//            if (isOK()) {
//                cout << l << "  ";
//                ans++;
//            }
//        }
//        cout << endl << ans << endl;
    }
    return 0;
}
0