結果
| 問題 | No.1704 Many Bus Stops (easy) |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-11-21 12:42:35 |
| 言語 | C++23(gcc16) (gcc 16.2.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 139 ms / 2,000 ms |
| + 688µs | |
| コード長 | 16,074 bytes |
| 記録 | |
| コンパイル時間 | 6,702 ms |
| コンパイル使用メモリ | 401,484 KB |
| 実行使用メモリ | 9,908 KB |
| 最終ジャッジ日時 | 2026-11-21 12:42:49 |
| 合計ジャッジ時間 | 13,310 ms |
|
ジャッジサーバーID (参考情報) |
judge4_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 41 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
constexpr long long INF=2002002002002002002LL;
constexpr double PI=3.14159265358979323846;
constexpr long long dx[]={ 1, 0, -1, 0, 1, -1, -1, 1, 0};
constexpr long long dy[]={ 0, 1, 0, -1, 1, 1, -1, -1, 0};
constexpr string yesno[]={"No\n","Yes\n"};
constexpr char DRUL[]="DRUL";
constexpr unsigned long long TEN[]={1,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000,10000000000,100000000000,1000000000000,10000000000000,100000000000000,1000000000000000,10000000000000000,100000000000000000,1000000000000000000,10000000000000000000ULL};
using ll=long long;
using ull=unsigned long long;
using mint=atcoder::modint998244353;
template<class T> using min_priority_queue=priority_queue<T,vector<T>,greater<T>>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class U,class V> pair<U,V> operator+(const pair<U,V> &lhs, const pair<U,V> &rhs) { return {lhs.first+rhs.first,lhs.second+rhs.second}; }
template<class U,class V> pair<U,V> operator-(const pair<U,V> &lhs, const pair<U,V> &rhs) { return {lhs.first-rhs.first,lhs.second-rhs.second}; }
template<class U,class V> pair<U,V> &operator+=(pair<U,V> &lhs, const pair<U,V> &rhs) { return lhs=lhs+rhs; }
template<class U,class V> pair<U,V> &operator-=(pair<U,V> &lhs, const pair<U,V> &rhs) { return lhs=lhs-rhs; }
template<class T> pair<T,T> operator*(const pair<T,T> &lhs, const T &rhs) { return {lhs.first*rhs,lhs.second*rhs}; }
template<class T> pair<T,T> operator*(const T &lhs, const pair<T,T> &rhs) { return {lhs*rhs.first,lhs*rhs.second}; }
template<class T> pair<T,T> operator/(const pair<T,T> &lhs, const T &rhs) { return {lhs.first/rhs,lhs.second/rhs}; }
template<class T> T operator*(const pair<T,T> &lhs, const pair<T,T> &rhs) { return lhs.first*rhs.second-rhs.first*lhs.second; }
template<class T> inline T hypotsq(const pair<T,T> &p) { return p.first*p.first+p.second*p.second; }
template<class T> inline double hypot(const pair<T,T> &p) { return hypot<double>(p.first,p.second); }
template<class T> inline T hypotsq(T x, T y) { return x*x+y*y; }
template<class T> inline T hypotsq(T px, T py, T qx, T qy) { return hypotsq(qx-px,qy-py); }
template<class T> inline double hypot(T px, T py, T qx, T qy) { return hypot<double>(qx-px,qy-py); }
template<int M> istream &operator>>(istream &is, atcoder::static_modint<M> &x) { long long _x; is>>_x; x=_x; return is; }
template<int M> ostream &operator<<(ostream &os, const atcoder::static_modint<M> &x) { return os<<x.val(); }
template<int M> istream &operator>>(istream &is, atcoder::dynamic_modint<M> &x) { long long _x; is>>_x; x=_x; return is; }
template<int M> ostream &operator<<(ostream &os, const atcoder::dynamic_modint<M> &x) { return os<<x.val(); }
istream &operator>>(istream &is, __int128_t &x) { string S; is>>S; x=0; bool neg=false; for (auto &c : S) { if (c=='-') neg=true; else x=x*10+c-'0'; } if (neg) x=-x; return is; }
ostream &operator<<(ostream &os, __int128_t x) { if (x==0) return os<<0; if (x<0) os<<'-', x=-x; string S; while (x) S.push_back('0'+x%10), x/=10; reverse(begin(S),end(S)); return os<<S; }
istream &operator>>(istream &is, __uint128_t &x) { string S; is>>S; x=0; for (auto &c : S) x=x*10+c-'0'; return is; }
ostream &operator<<(ostream &os, __uint128_t x) { if (x==0) return os<<0; string S; while (x) S.push_back('0'+x%10), x/=10; reverse(begin(S), end(S)); return os<<S; }
template<class U,class V> istream &operator>>(istream &is, pair<U,V> &p);
template<class U,class V> ostream &operator<<(ostream &os, const pair<U,V> &p);
template<class ...T> istream &operator>>(istream &is, tuple<T...> &t);
template<class ...T> ostream &operator<<(ostream &os, const tuple<T...> &t);
template<class T> istream &operator>>(istream &is, vector<T> &v);
template<class T> ostream &operator<<(ostream &os, const vector<T> &v);
template<class T> ostream &operator<<(ostream &os, const optional<T> &x);
template<class U,class V> istream &operator>>(istream &is, pair<U,V> &p) { return is>>p.first>>p.second; }
template<class U,class V> ostream &operator<<(ostream &os, const pair<U,V> &p) { return os<<p.first<<' '<<p.second; }
template<class ...T> istream &operator>>(istream &is, tuple<T...> &t) { apply([&](auto &...args) { ((is>>args), ...); },t); return is; }
template<class ...T> ostream &operator<<(ostream &os, const tuple<T...> &t) { apply([&](auto &...args) { int n=0; ((os<<(n++?" ":"")<<args), ...); },t); return os;}
template<class T> istream &operator>>(istream &is, vector<T> &v) { for (auto &x : v) is>>x; return is; }
template<class T> ostream &operator<<(ostream &os, const vector<T> &v) { for (int i=0,s=(int)v.size();i<s;++i) os<<(i?" ":"")<<v[i]; return os; }
template<class T> ostream &operator<<(ostream &os, const set<T> &v) { auto it=v.begin(); while (it!=v.end()) os<<*it++<<(it==v.end()?"":" "); return os; }
template<class T> ostream &operator<<(ostream &os, const unordered_set<T> &v) { auto it=v.begin(); while (it!=v.end()) os<<*it++<<(it==v.end()?"":" "); return os; }
template<class T> ostream &operator<<(ostream &os, const multiset<T> &v) { auto it=v.begin(); while (it!=v.end()) os<<*it++<<(it==v.end()?"":" "); return os; }
template<class T> ostream &operator<<(ostream &os, const list<T> &v) { auto it=v.begin(); while (it!=v.end()) os<<*it++<<(it==v.end()?"":" "); return os; }
template<class T> ostream &operator<<(ostream &os, const stack<T> &v) { stack<T> u=v; while (!u.empty()) { os<<u.top(); u.pop(); if (!u.empty()) os<<' '; } return os; }
template<class T> ostream &operator<<(ostream &os, const queue<T> &v) { queue<T> u=v; while (!u.empty()) { os<<u.front(); u.pop(); if (!u.empty()) os<<' '; } return os; }
template<class T> ostream &operator<<(ostream &os, const deque<T> &v) { deque<T> u=v; while (!u.empty()) { os<<u.front(); u.pop_front(); if (!u.empty()) os<<' '; } return os; }
template<class T,class U,class V> ostream &operator<<(ostream &os, const priority_queue<T,U,V> &v) { priority_queue<T,U,V> u=v; while (!u.empty()) { os<<u.top(); u.pop(); if (!u.empty()) os<<' '; } return os; }
template<class T,class U> ostream &operator<<(ostream &os, const map<T,U> &m) { auto it=m.begin(); while (it!=m.end()) os<<(it->first)<<':'<<(it++->second)<<(it==m.end()?"":" "); return os; }
template<class T,class U> ostream &operator<<(ostream &os, const unordered_map<T,U> &m) { auto it=m.begin(); while (it!=m.end()) os<<(it->first)<<':'<<(it++->second)<<(it==m.end()?"":" "); return os; }
template<class T> ostream &operator<<(ostream &os, const optional<T> &x) { if (x.has_value()) return os<<x.value(); return os<<"-1"; }
template<class T,class U> inline T floor(const T &a, const U &b) { return a/b-(a%b && (a^b)< 0); }
template<class T,class U> inline T ceil (const T &a, const U &b) { return a/b+(a%b && (a^b)>=0); }
inline double radian(double deg) { return (PI/180.0)*deg; }
inline double degree(double rad) { return (180.0/PI)*rad; }
inline long long popcount(unsigned long long x) { return __builtin_popcountll(x); }
inline long long height(unsigned long long x) { if (x==0) return 0LL; return 64LL-__builtin_clzll(x); }
inline long long ctz(unsigned long long x) { return __builtin_ctzll(x); }
inline long long lsb(long long b) { return b&-b; }
template<class T> long long sgn(const T &x) { if (x<0) return -1; return x>0; }
template<class T> inline typename enable_if<is_integral_v<T>,T>::type rem(T a, T b) { assert(b>0); T res=a%b; if (res<0) res+=b; return res; }
template<class T> inline typename enable_if<is_floating_point_v<T>,T>::type rem(T a, T b) { assert(b>0); T res=a-floor(a/b)*b; if (res<0.0) res+=b; return res; }
template<class T> inline bool inlr(const T &l, const T &x, const T &r) noexcept { return (l<=x && x<r); }
template<class T> bool isinc(T first, T second) { return first<=second; }
template<class T,class ...Rest> bool isinc(T first, T second, const Rest ...rest) { return first<=second && isinc(second,rest...); }
long long safe_mul() noexcept { return 1LL; }
template<class ...Rest> long long safe_mul(long long a, Rest ...rest) noexcept { if (a==0LL) return 0LL; long long b=safe_mul(rest...); if (b==0LL) return 0LL; if (INF/a/b==0LL) return ((0LL<a)^(0LL<b) ? -INF : INF); return a*b; }
template<class T> void println(T item) { cout<<item<<'\n'; }
template<class T,class ...Rest> void println(T item, Rest ...rest) { cout<<item<<' '; println(rest...); }
template<class T> void dump(T item) { cerr<<item<<'\n'; }
template<class T,class ...Rest> void dump(T item, Rest ...rest) { cerr<<item<<' '; dump(rest...); }
long long safe_lcm(long long a, long long b) { if (a==0 || b==0) return 0LL; if (a<0) a=-a; if (b<0) b=-b; if (a>=INF || b>=INF) return INF; return safe_mul(a/gcd(a,b),b); }
template<class Res=long long> vector<Res> mkiota(int n, Res val=0) { vector<Res> res(n); iota(begin(res),end(res),val); return res; }
template<class T> T mkrev(const T &v) { T res=v; reverse(res.begin(),res.end()); return res; }
template<class T> vector<T> mksum(const vector<T> &v) { int s=v.size(); vector<T> res(s+1); for (int i=0;i<s;++i) res[i+1]=res[i]+v[i]; return res; }
template<class T> vector<T> mkdif(const vector<T> &v) { int s=v.size(); vector<T> res(s-1); for (int i=0;i+1<s;++i) res[i]=v[i+1]-v[i]; return res; }
template<class T> vector<T> mkuni(const vector<T> &v) { auto res=v; sort(res.begin(),res.end()); res.erase(unique(res.begin(),res.end()),res.end()); return res; }
template<class Res=long long,class T> vector<Res> mkinv(const vector<T> &v) { vector<Res> res(*max_element(v.begin(),v.end())+1,-1); for (int i=0,s=v.size();i<s;++i) res[v[i]]=i; return res; }
template<class Res=long long,class F> vector<Res> mkord(int n, F f) { vector<Res> res(n); iota(res.begin(),res.end(),0); stable_sort(res.begin(),res.end(),f); return res; }
template<class T> map<T,long long> mkcnt(const vector<T> &v) { map<T,long long> res; for (const auto &x : v) res[x]++; return res; }
template<class T,class F> vector<vector<T>> mksplit(const vector<T> &v, F f) { if (v.size()==0) return {}; vector<vector<T>> res{{v[0]}}; for (int i=0,s=v.size();i+1<s;++i) { if (f(v[i],v[i+1])) res.push_back({}); res.back().push_back(v[i+1]); } return res; }
template<class T> vector<pair<T,long long>> mkrle(const vector<T> &v) { int n=v.size(); vector<pair<T,long long>> res; for (int i=0;i<n;++i) { long long cnt=1; while (i+1<n && v[i]==v[i+1]) { cnt++; i++; } res.emplace_back(v[i],cnt); } return res; }
vector<pair<char,long long>> mkrle(const string &s) { int n=s.size(); vector<pair<char,long long>> res; for (int i=0;i<n;++i) { long long cnt=1; while (i+1<n && s[i]==s[i+1]) { cnt++; i++; } res.emplace_back(s[i],cnt); } return res; }
template<class T> atcoder::fenwick_tree<T> mkfen(const vector<T> &v) { int s=v.size(); atcoder::fenwick_tree<T> res(s); for (int i=0;i<s;++i) res.add(i,v[i]); return res; }
template<class T> T min(const vector<T> &v) { return *min_element(v.begin(),v.end()); }
template<class T> T max(const vector<T> &v) { return *max_element(v.begin(),v.end()); }
template<class T> inline void sort(T &v, bool rev=false) { rev ? sort(v.rbegin(),v.rend()) : sort(v.begin(),v.end()); }
template<class T,class U> long long count(const T &v, const U &item) { return count(v.begin(),v.end(),item); }
template<class T> inline long long count_in_range(const vector<T> &v, const T &l, const T &r) { return lower_bound(v.begin(),v.end(),r)-lower_bound(v.begin(),v.end(),l); }
template<class T> inline long long lob(const vector<T> &v, const T &x) { return lower_bound(v.begin(),v.end(),x)-v.begin(); }
template<class T> inline long long upb(const vector<T> &v, const T &x) { return upper_bound(v.begin(),v.end(),x)-v.begin(); }
template<class T> optional<long long> minel(const vector<T> &v, size_t k=0) { if (v.size()<=k) return nullopt; return mkord(v.size(),[&](long long a, long long b)->bool { return v[a]<v[b]; })[k]; }
template<class T> optional<long long> maxel(const vector<T> &v, size_t k=0) { if (v.size()<=k) return nullopt; return mkord(v.size(),[&](long long a, long long b)->bool { return v[a]>v[b]; })[k]; }
template<class T> T flatten(const vector<T> &vv) { T res; for (const T &v : vv) res.insert(res.end(),v.begin(),v.end()); return res; }
vector<long long> binary_split(long long x) { assert(x>=0); vector<long long> res; long long k=1; while (x>0) { long long y=min(k,x); res.push_back(y); x-=y; k<<=1; } return res; }
template<class T> T arithmetic_series(T a, T d, T n) { return (a*2+(n-1)*d)*n/2; }
template<class T> long long hamming_distance(const T &a, const T &b) { assert(a.size()==b.size()); auto ita=a.begin(); auto itb=b.begin(); int res=0; while (ita!=a.end()) if (*ita++!=*itb++) res++; return res; }
template<class T> long long get_period(const T &v) { int n=v.size(); vector<int> z=atcoder::z_algorithm(v); for (int i=1;i<=n/2;++i) if (n%i==0 && z[i]==n-i) return i; return n; }
template<class T> void cumulative_min(vector<T> &v, bool ltr) { int n=v.size(); if (ltr) for (int i=0;i+1<n;++i) v[i+1]=min(v[i+1],v[i]); else for (int i=n-2;i>=0;--i) v[i]=min(v[i],v[i+1]); }
template<class T> void cumulative_max(vector<T> &v, bool ltr) { int n=v.size(); if (ltr) for (int i=0;i+1<n;++i) v[i+1]=max(v[i+1],v[i]); else for (int i=n-2;i>=0;--i) v[i]=max(v[i],v[i+1]); }
template<class T> void repeat_vector(vector<T> &v, int count=2) { assert(count>=0); if (count==0) { v.clear(); return; } count--; int original_size=v.size(); while (count--) v.insert(v.end(),v.begin(),v.begin()+original_size); }
template<class T> long long longest_continuum(const vector<T> &v) { if (v.empty()) return 0; long long res=1; long long now=1; int n=v.size(); for (int i=1;i<n;++i) if (v[i]==v[i-1]) chmax(res,++now); else now=1; return res; }
template<class T> long long longest_continuum(const vector<T> &v, const T &item) { long long res=0; long long now=0; for (auto &x : v) if (x==item) chmax(res,++now); else now=0; return res; }
template<class T> long long lis_len(const vector<T> &v, bool strict=true) { vector<T> dp; for (auto &x : v) { auto it=strict ? lower_bound(dp.begin(),dp.end(),x) : upper_bound(dp.begin(),dp.end(),x); if (it==dp.end()) dp.push_back(x); else *it=x; } return dp.size(); }
template<class T> long long inversions(vector<T> &v) { map<T,int> cc; for (auto &x : v) cc[x]=0; int M=0; for (auto &[key,val] : cc) val=M++; long long res=0; atcoder::fenwick_tree<long long> fen(M); for (auto &x : v) { int y=cc[x]; res+=fen.sum(y+1,M); fen.add(y,1); } return res; }
long long ctok(char d) { switch (d) { case 'D': return 0; case 'R': return 1; case 'U': return 2; case 'L': return 3; } return -1; }
template<class T> T min_op(T a, T b) { return min(a,b); }
template<class T> T max_op(T a, T b) { return max(a,b); }
template<class T> using min_segtree=atcoder::segtree<T,min_op<T>,numeric_limits<T>::max>;
template<class T> using max_segtree=atcoder::segtree<T,max_op<T>,numeric_limits<T>::lowest>;
template<typename T> vector<vector<T>> matrix_pow(vector<vector<T>> x, long long y) {
assert(y>=0);
int N=x.size();
if (y==0) {
vector<vector<T>> res(N,vector<T>(N,0));
for (int i=0;i<N;++i) res[i][i]=1;
return res;
}
auto prod=[&](vector<vector<T>> a, vector<vector<T>> b)->vector<vector<T>> {
vector<vector<T>> res(N,vector<T>(N,0));
for (int i=0;i<N;++i) {
for (int j=0;j<N;++j) {
for (int k=0;k<N;++k) {
res[i][j]+=a[i][k]*b[k][j];
}
}
}
return res;
};
if (y%2==1) return prod(x,matrix_pow(x,y-1));
return matrix_pow(prod(x,x),y/2);
}
int main() {
using mint=atcoder::modint1000000007;
vector<vector<mint>> mat(6,vector<mint>(6,0));
const mint THIRD=mint(3).inv();
mat[0][0]=THIRD;
mat[1][1]=THIRD;
mat[2][2]=THIRD;
mat[0][4]=THIRD;
mat[0][5]=THIRD;
mat[1][3]=THIRD;
mat[1][5]=THIRD;
mat[2][3]=THIRD;
mat[2][4]=THIRD;
mat[3][0]=1;
mat[4][1]=1;
mat[5][2]=1;
ll T;
cin>>T;
while (T--) {
ll N;
cin>>N;
cout<<matrix_pow(mat,N)[0][0]<<'\n';
}
}