結果
問題 | No.1706 Many Bus Stops (hard) |
ユーザー |
![]() |
提出日時 | 2021-10-08 23:41:45 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 8 ms / 2,000 ms |
コード長 | 1,838 bytes |
コンパイル時間 | 2,291 ms |
コンパイル使用メモリ | 194,928 KB |
最終ジャッジ日時 | 2025-01-24 23:34:21 |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 41 |
ソースコード
#include <bits/stdc++.h>using namespace std;typedef signed long long ll;#define _P(...) (void)printf(__VA_ARGS__)#define FOR(x,to) for(x=0;x<(to);x++)#define FORR(x,arr) for(auto& x:arr)#define FORR2(x,y,arr) for(auto& [x,y]:arr)#define ALL(a) (a.begin()),(a.end())#define ZERO(a) memset(a,0,sizeof(a))#define MINUS(a) memset(a,0xff,sizeof(a))template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}//-------------------------------------------------------const int MAT=5;struct Mat { ll v[MAT][MAT]; Mat(){ZERO(v);};};const ll mo=1000000007;ll modpow(ll a, ll n = mo-2) {ll r=1;a%=mo;while(n) r=r*((n%2)?a:1)%mo,a=a*a%mo,n>>=1;return r;}Mat mulmat(Mat& a,Mat& b,int n=MAT) {ll mo2=4*mo*mo;int x,y,z; Mat r;FOR(x,n) FOR(y,n) r.v[x][y]=0;FOR(x,n) FOR(z,n) FOR(y,n) {r.v[x][y] += a.v[x][z]*b.v[z][y];if(r.v[x][y]>mo2) r.v[x][y] -= mo2;}FOR(x,n) FOR(y,n) r.v[x][y]%=mo;return r;}Mat powmat(ll p,Mat a,int n=MAT) {int i,x,y; Mat r;FOR(x,n) FOR(y,n) r.v[x][y]=0;FOR(i,n) r.v[i][i]=1;while(p) {if(p%2) r=mulmat(r,a,n);a=mulmat(a,a,n);p>>=1;}return r;}int C,N,M;void solve() {int i,j,k,l,r,x,y; string s;cin>>C>>N>>M;Mat A;// A,notA,A->notA,notA->A,notA->notAA.v[0][0]=modpow(C);A.v[2][0]=1+mo-modpow(C);A.v[1][1]=modpow(C);A.v[3][1]=modpow(C);A.v[4][1]=(1-2*modpow(C)+2*mo)%mo;A.v[1][2]=1;A.v[0][3]=1;A.v[1][4]=1;A=powmat(N,A);ll notA=1+mo-A.v[0][0];ll ret=1-modpow(notA,M)+mo;cout<<ret%mo<<endl;}int main(int argc,char** argv){string s;int i;if(argc==1) ios::sync_with_stdio(false), cin.tie(0);FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);cout.tie(0); solve(); return 0;}