結果
問題 | No.1717 Levi-Civita Triangle |
ユーザー | riano |
提出日時 | 2021-10-22 22:57:58 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 23 ms / 2,000 ms |
コード長 | 3,494 bytes |
コンパイル時間 | 1,669 ms |
コンパイル使用メモリ | 171,704 KB |
実行使用メモリ | 11,040 KB |
最終ジャッジ日時 | 2024-09-23 06:49:37 |
合計ジャッジ時間 | 3,333 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 42 |
ソースコード
#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; }