結果

問題 No.1717 Levi-Civita Triangle
ユーザー rianoriano
提出日時 2021-10-22 22:57:58
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 23 ms / 2,000 ms
コード長 3,494 bytes
コンパイル時間 1,883 ms
コンパイル使用メモリ 172,548 KB
実行使用メモリ 11,016 KB
最終ジャッジ日時 2023-10-24 14:28:21
合計ジャッジ時間 3,799 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,368 KB
testcase_01 AC 2 ms
4,368 KB
testcase_02 AC 2 ms
4,368 KB
testcase_03 AC 1 ms
4,368 KB
testcase_04 AC 1 ms
4,368 KB
testcase_05 AC 2 ms
4,368 KB
testcase_06 AC 4 ms
4,368 KB
testcase_07 AC 15 ms
7,384 KB
testcase_08 AC 2 ms
4,368 KB
testcase_09 AC 2 ms
4,368 KB
testcase_10 AC 2 ms
4,368 KB
testcase_11 AC 4 ms
4,368 KB
testcase_12 AC 10 ms
6,336 KB
testcase_13 AC 2 ms
4,368 KB
testcase_14 AC 2 ms
4,368 KB
testcase_15 AC 2 ms
4,368 KB
testcase_16 AC 3 ms
4,368 KB
testcase_17 AC 18 ms
9,744 KB
testcase_18 AC 2 ms
4,368 KB
testcase_19 AC 2 ms
4,368 KB
testcase_20 AC 2 ms
4,368 KB
testcase_21 AC 3 ms
4,368 KB
testcase_22 AC 14 ms
7,296 KB
testcase_23 AC 2 ms
4,368 KB
testcase_24 AC 2 ms
4,368 KB
testcase_25 AC 2 ms
4,368 KB
testcase_26 AC 2 ms
4,368 KB
testcase_27 AC 6 ms
4,912 KB
testcase_28 AC 1 ms
4,368 KB
testcase_29 AC 2 ms
4,368 KB
testcase_30 AC 2 ms
4,368 KB
testcase_31 AC 3 ms
4,368 KB
testcase_32 AC 20 ms
10,168 KB
testcase_33 AC 22 ms
11,016 KB
testcase_34 AC 22 ms
11,016 KB
testcase_35 AC 23 ms
11,016 KB
testcase_36 AC 23 ms
11,016 KB
testcase_37 AC 23 ms
11,016 KB
testcase_38 AC 22 ms
11,016 KB
testcase_39 AC 22 ms
11,016 KB
testcase_40 AC 22 ms
11,016 KB
testcase_41 AC 22 ms
11,016 KB
testcase_42 AC 23 ms
11,016 KB
testcase_43 AC 23 ms
11,016 KB
testcase_44 AC 23 ms
11,016 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Pr pair<ll,ll>
#define Tp tuple<int,int,int>
#define all(v) v.begin(),v.end()
#define riano_ std::ios::sync_with_stdio(false);std::cin.tie(nullptr)
using Graph = vector<vector<ll>>;

const ll mod = 8e18;
template<uint64_t mod>
struct modint{
    uint64_t val;
    constexpr modint(const int64_t val_=0) noexcept:val((val_%int64_t(mod)+int64_t(mod))%int64_t(mod)){}
    constexpr modint operator-() const noexcept{
        return modint(*this)=mod-val;
    }
    constexpr modint operator+(const modint rhs) const noexcept{
        return modint(*this)+=rhs;
    }
    constexpr modint operator-(const modint rhs) const noexcept{
        return modint(*this)-=rhs;
    }
    constexpr modint operator*(const modint rhs) const noexcept{
        return modint(*this)*=rhs;
    }
    constexpr modint operator/(const modint rhs) const noexcept{
        return modint(*this)/=rhs;
    }
    constexpr modint &operator+=(const modint rhs) noexcept{
        val+=rhs.val;
        val-=((val>=mod)?mod:0);
        return (*this);
    }
    constexpr modint &operator-=(const modint rhs) noexcept{
        val+=((val<rhs.val)?mod:0);
        val-=rhs.val;
        return (*this);
    }
    constexpr modint &operator*=(const modint rhs) noexcept{
        val=val*rhs.val%mod;
        return (*this);
    }
    constexpr modint &operator/=(modint rhs) noexcept{
        uint64_t ex=mod-2;
        modint now=1;
        while(ex){
            now*=((ex&1)?rhs:1);
            rhs*=rhs,ex>>=1;
        }
        return (*this)*=now;
    }
    modint & operator++(){
        val++;
        if (val == mod) val = 0;
        return *this;
    }
    modint operator++(int){
        modint<mod> res = *this;
        ++*this;
        return res;
    }
    constexpr bool operator==(const modint rhs) noexcept{
        return val==rhs.val;
    }
    constexpr bool operator!=(const modint rhs) noexcept{
        return val!=rhs.val;
    }
    friend constexpr ostream &operator<<(ostream& os,const modint x) noexcept{
        return os<<(x.val);
    }
    friend constexpr istream &operator>>(istream& is,modint& x) noexcept{
        uint64_t t;
        is>>t,x=t;
        return is;
    }
};
typedef modint<mod> mint;

vector<ll> convert(vector<ll> a){
    vector<ll> res;
    int N = a.size();
    ll acm = 0;
    rep(i,N-1){
        a[i+1] += acm;
        if(a[i+1]<a[i]){
            a[i+1] += 3; acm += 3;
        }
    }
    rep(i,N-2){
        if(a[i+1]-a[i]==a[i+2]-a[i+1]){
            res.push_back(a[i+1]-a[i]);
        }
        else res.push_back(0);
    }
    return res;
}

int main() {
    riano_; ll ans = 0;
    ll N; cin >> N;
    N = N*2+1;
    vector<ll> a;
    rep(i,N){
        ll b; cin >> b;
        a.push_back(b);
    }
    if(N==1){
        cout << a[0] << endl; return 0;
    }
    if(N==3){
        cout << convert(a)[0] << endl; return 0;
    }
    auto v = convert(convert(a));
    N -= 4;
    ans = v[N-1];
    rep(i,N){
        if(i%2==1){
            if(v[i]!=0){
                cout << 0 << endl; return 0;
            }
        }
        else{
            if((N-1-i)%4==0){
                if(v[i]!=ans){
                    cout << 0 << endl; return 0;
                }
            }
            else{
                if(v[i]!=(3^ans)){
                    cout << 0 << endl; return 0;
                }
            }
        }
    }
    cout << ans << endl;
}
0