結果

問題 No.1717 Levi-Civita Triangle
ユーザー milanis48663220milanis48663220
提出日時 2021-10-22 23:28:00
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 17 ms / 2,000 ms
コード長 2,619 bytes
コンパイル時間 1,216 ms
コンパイル使用メモリ 124,292 KB
実行使用メモリ 6,576 KB
最終ジャッジ日時 2023-10-24 15:36:00
合計ジャッジ時間 2,760 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 3 ms
4,348 KB
testcase_07 AC 9 ms
4,480 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 3 ms
4,348 KB
testcase_12 AC 6 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 13 ms
6,012 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 10 ms
5,164 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 2 ms
4,348 KB
testcase_25 AC 2 ms
4,348 KB
testcase_26 AC 2 ms
4,348 KB
testcase_27 AC 6 ms
4,348 KB
testcase_28 AC 2 ms
4,348 KB
testcase_29 AC 1 ms
4,348 KB
testcase_30 AC 2 ms
4,348 KB
testcase_31 AC 3 ms
4,348 KB
testcase_32 AC 15 ms
6,132 KB
testcase_33 AC 16 ms
6,576 KB
testcase_34 AC 16 ms
6,576 KB
testcase_35 AC 17 ms
6,576 KB
testcase_36 AC 17 ms
6,576 KB
testcase_37 AC 17 ms
6,576 KB
testcase_38 AC 17 ms
6,576 KB
testcase_39 AC 16 ms
6,576 KB
testcase_40 AC 16 ms
6,576 KB
testcase_41 AC 17 ms
6,576 KB
testcase_42 AC 17 ms
6,576 KB
testcase_43 AC 17 ms
6,576 KB
testcase_44 AC 17 ms
6,576 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
typedef long long ll;

template<typename T>
void print_vector(vector<T> v, char delimiter=' '){
    if(v.empty()) {
        cout << endl;
        return;
    }
    for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter;
    cout << v.back() << endl;
}


vector<int> as_base3(int x, int n){
    vector<int> ans;
    for(int i = 0; i < n; i++){
        ans.push_back(x%3);
        x /= 3;
    }
    return ans;
}

int f(int a, int b, int c){
    if(a == b || b == c || c == a) return 0;
    int r = (3+b-a)%3;
    return r;
}

int calc(vector<int> v){
    if(v.size() == 1) return v[0];
    int n = v.size();
    vector<int> u;
    for(int i = 1; i < n-1; i++){
        u.push_back(f(v[i-1], v[i], v[i+1]));
    }
    return calc(u);
}

int solve(vector<int> a){
    int n = a.size()/2;
    vector<int> b(2*n);
    for(int i = 0; i < 2*n; i++) b[i] = (a[i+1]-a[i]+3)%3;
    // print_vector(b);
    for(int i = 0; i < 2*n; i++){
        if(b[i] == 0) return 0;
    }
    vector<int> c;
    for(int i = 0; i < n; i++){
        if(i%2 == 0) {
            c.push_back(b[0]);
            c.push_back(b[0]);
        }else{
            c.push_back(3-b[0]);
            c.push_back(3-b[0]);
        }
    }
    if(b != c) return 0;
    if(n%2 == 1){
        return b[0];
    }else{
        return 3-b[0];
    }
}

void test(int n){
    int mx = 1;
    for(int i = 0; i < n; i++) mx *= 3;
    for(int x = 0; x < mx; x++) {
        auto v = as_base3(x, n);
        // print_vector(v);
        // cout << calc(v) << ' ' << solve(v) << endl;
        // assert(calc(v) == solve(v));
        if(calc(v) != 0) {
            print_vector(v);
            cout << calc(v) << ' ' << solve(v) << endl;
        }else{
            assert(solve(v) == 0);
        }
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int n; cin >> n;
    // test(n);
    vector<int> a(2*n+1);
    for(int i = 0; i < 2*n+1; i++) cin >> a[i];
    cout << solve(a) << endl;
}
0