QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#722604 | #9491. 生命的循环 | WrongAnswer_90 | 1 | 169ms | 15116kb | C++23 | 7.9kb | 2024-11-07 19:38:29 | 2024-11-07 19:38:30 |
Judging History
answer
#include<bits/stdc++.h>
#define ull unsigned long long
#define ui unsigned int
#define ld long double
#define ll long long
#define lll __int128
#define fi first
#define se second
#define e emplace
#define eb emplace_back
#define db double
#define ef emplace_front
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vll vector<ll>
#define vp vector<pii>
#define vt vector<tup>
#define all(x) x.begin(),x.end()
#define mp make_pair
#define FastI
#define FastO
//#define int ll
bool ST;
static const ll MOD=1e9+9,Phi=998244352,inv2=499122177,Root=3,iRoot=332748118;
static const ll inf=1073741823,Inf=4294967296,INF=4557430888798830399;
static const ld eps=1e-9,pi=3.1415926535;
char in[1<<20],*p1=in,*p2=in;
char out[1<<20],*p3=out;
using namespace std;
struct tup
{
int x,y,z;
tup(int X=0,int Y=0,int Z=0)
{x=X,y=Y,z=Z;}
inline bool operator <(const tup t)const
{return x<t.x||(x==t.x&&y<t.y)
||(x==t.x&&y==t.y&&z<t.z);}
};
#ifdef FastI
#define getchar() (p1==p2&&(p2=(p1=in)+fread(in,1,1<<20,stdin),p1==p2)?EOF:*p1++)
#endif
#ifdef FastO
#define putchar(x) (p3-out==1<<20?fwrite(out,1,1<<20,stdout),p3=out,0:0,*p3++=x)
#define puts(x) write(x,'\n')
#endif
namespace FastIO
{
template<typename T> inline void write(T x,char ch=' ')
{
if(is_same<char,T>::value)putchar(x);
else
{
if(x<0)x=-x,putchar('-');
static char st[40];
int top=0;
do st[top++]=x%10+'0',x/=10;while(x);
while(top)putchar(st[--top]);
}
ch!='~'?putchar(ch):0;
}
inline void write(const char*x,char ch=' ')
{
for(int i=0;x[i]!='\0';++i)putchar(x[i]);
ch!='~'?putchar(ch):0;
}
inline void read(char&s){do s=getchar();while(s=='\n'||s==' ');}
inline void read(char s[])
{
int len=0;char st;
do st=getchar();while(st=='\n'||st==' ');
s[++len]=st,st=getchar();
while(st!='\n'&&st!=' '&&st!='\r'&&st!='\0')s[++len]=st,st=getchar();
s[++len]='\0';
}
template<typename T> inline void read(T &s)
{
char ch=getchar();s=0;
while((ch>'9'||ch<'0')&&ch!='-')ch=getchar();
bool tf=(ch=='-'&&(ch=getchar()));
while(ch>='0'&&ch<='9')s=(s<<1)+(s<<3)+ch-'0',ch=getchar();
s=tf?-s:s;
}
inline void edl(){putchar('\n');}
template<typename T1,typename T2> inline void read(pair<T1,T2> &s){read(s.fi),read(s.se);}
template<typename T,typename...Args> inline void write(T x,Args...args){write(x,'~'),write(args...);}
template<typename T,typename...Args> inline void read(T&x,Args&...args){read(x),read(args...);}
#ifdef FastO
struct Writer{~Writer(){fwrite(out,1,p3-out,stdout);}}Writ;
#endif
}
using namespace FastIO;
namespace MTool
{
inline int Cadd(int a,int b){return (ll)a+b>=MOD?(ll)a+b-MOD:a+b;}
inline int Cdel(int a,int b){return a-b<0?a-b+MOD:a-b;}
inline int Cmul(int a,int b){return 1ll*a*b%MOD;}
inline int sqr(int a){return 1ll*a*a%MOD;}
inline void Madd(int&a,int b){a=((ll)a+b>=MOD?(ll)a+b-MOD:a+b);}
inline void Mdel(int&a,int b){a=(a-b<0?a-b+MOD:a-b);}
inline void Mmul(int&a,int b){a=1ll*a*b%MOD;}
inline int Cmod(int x){return (x%MOD+MOD)%MOD;}
inline void Mmod(int&x){x=(x%MOD+MOD)%MOD;}
template<typename T> inline bool Mmax(T&a,T b){return a<b?a=b,1:0;}
template<typename T> inline bool Mmin(T&a,T b){return a>b?a=b,1:0;}
template<typename...Args> inline void Madd(int&a,int b,Args...args){Madd(a,b),Madd(a,args...);}
template<typename...Args> inline void Mmul(int&a,int b,Args...args){Mmul(a,b),Mmul(a,args...);}
template<typename...Args> inline void Mdel(int&a,int b,Args...args){Mdel(a,b),Mdel(a,args...);}
template<typename...Args> inline int Cadd(int a,int b,Args...args){return Cadd(Cadd(a,b),args...);}
template<typename...Args> inline int Cmul(int a,int b,Args...args){return Cmul(Cmul(a,b),args...);}
template<typename...Args> inline int Cdel(int a,int b,Args...args){return Cdel(Cdel(a,b),args...);}
template<typename...Args,typename T> inline bool Mmax(T&a,T b,Args...args){return Mmax(a,b)|Mmax(a,args...);}
template<typename...Args,typename T> inline bool Mmin(T&a,T b,Args...args){return Mmin(a,b)|Mmin(a,args...);}
inline int power(int x,int y){int s=1;for(;y;y>>=1,Mmul(x,x))if(y&1)Mmul(s,x);return s;}
}
using namespace MTool;
namespace WrongAnswer_90
{
int n,m,C;
bitset<110> f[5010][110],g[5010][110],h[110],vis,can[110];
tup a[10010];
vp G[5010];
int d[5010];
int tot,dfn[5010],low[5010];
int num,c[5010],sum[5010];
int ins[5010];
vi ve[5010];
stack<int> st;
void tarjan(int x)
{
st.e(x),ins[x]=1,dfn[x]=low[x]=++tot;
for(auto [to,v]:G[x])
{
if(!dfn[to])tarjan(to),low[x]=min(low[x],low[to]);
else if(ins[to])low[x]=min(low[x],dfn[to]);
}
if(dfn[x]==low[x])
{
int y;++num;
do
{
y=st.top(),st.pop();
c[y]=num,ins[y]=0;
ve[num].eb(y);
}while(y!=x);
}
}
inline int Gcd(int x,int y){return !x||!y?(x^y):__gcd(x,y);}
inline int calc(int x,int y)
{
int s=0;
while(x%y==0)++s,x/=y;
return s;
}
int tmp=0;
void dfs(int x)
{
for(auto [to,v]:G[x])if(c[to]==c[x])
{
if(d[to]==-1)d[to]=d[x]+v,dfs(to);
else tmp=Gcd(tmp,abs(d[x]-d[to]+v));
}
}
void upd(int x,int y,int z)
{
if(f[x][y][z])return;
f[x][y][z]=1;
if(sum[x]!=0)return;
for(auto [to,v]:G[x])upd(to,y,(z+v)%y);
}
void upd2(int x,int y,int z)
{
if(g[x][y][z])return;
g[x][y][z]=1;
for(auto [to,v]:G[x])
{
int V=Gcd(y,sum[to]);
upd2(to,V,(z+v)%V);
}
}
int nex[110];
int get(int id)
{
for(int i=2,j=0;i<=id;++i)
{
while(j&&h[id][j+1]!=h[id][i])j=nex[j];
if(h[id][j+1]==h[id][i])++j;
nex[i]=j;
}
if(id%(id-nex[id])==0)return id-nex[id];
return id;
}
const int B=2520;
bitset<110> use[110],real[110];
void mian()
{
read(n,m,C);
int x,y,z;
for(int i=1;i<=m;++i)
{
read(x,y,z),a[i]=tup(x,y,z);
G[x].eb(mp(y,z));
}
for(int i=1;i<=n;++i)if(!dfn[i])tarjan(i);
memset(d,-1,sizeof(d));
for(int i=1;i<=num;++i)
{
tmp=0;
d[ve[i][0]]=0;
dfs(ve[i][0]);
for(auto p:ve[i])sum[p]=tmp;
}
for(int i=1;i<=100;++i)upd(1,i,0);
for(int i=1;i<=n;++i)if(sum[i])
{
for(int k=0;k<sum[i];++k)if(f[i][sum[i]][k])
upd2(i,sum[i],k);
}
for(int i=1;i<=100;++i)h[i]=~(g[n][i]<<1);
for(int r=0;r<B;++r)
{
for(int i=1;i<=100;++i)for(int j=0;j<i;++j)use[i][j]=1;
for(int i=1;i<=100;++i)
{
int d=i/Gcd(i,B);
for(int j=0;j<d;++j)
use[d][j]=use[d][j]&h[i][(j*B+r)%i+1];
}
int flag=1;
for(int i=1;i<=100;++i)
{
for(int j=i+i;j<=100;j+=i)
{
for(int k=0;k<j;++k)
use[j][k]=use[j][k]&use[i][k%i];
}
int fl=0;
for(int j=0;j<i;++j)fl|=use[i][j];
if(!fl){flag=0;break;}
}
if(flag)for(int i=1;i<=100;++i)real[r%i]=1;
}
for(int i=1;i<=100;++i)
{
int d=i/Gcd(i,B);
for(int j=0;j<100;++j)if(real[i][j])
{
for(int k=0;k<d;++k)
can[i][(k*B+j)%i+1]=1;
}
}
for(int i=1;i<=100;++i)h[i]&=can[i];
// for(int i=1;i<=100;++i,cerr<<endl)for(int j=1;j<=i;++j)
// cerr<<h[i][j];
for(int i=1;i<=100;++i)
{
for(int j=i+i;j<=100;j+=i)
{
for(int k=1;k<=j;++k)
h[j][k]=h[j][k]&h[i][(k-1)%i+1];
}
}
vi ans;
for(int i=100;i>=1;--i)
{
int tmp=get(i);
if(tmp==i)ans.eb(i);
else h[tmp]&=h[i];
}
if(h[1][1]==0)return puts("1");
int Ans=1;
for(int i=2;i<=100;++i)if(!vis[i])
{
int v=0;
for(auto p:ans)Mmax(v,calc(p,i));
Mmul(Ans,power(i,v));
for(int j=i+i;j<=100;j+=i)vis[j]=1;
}
write(Ans,'~');
}
inline void Mian()
{
int T=1;
// read(T);
while(T--)mian();
}
}
bool ED;
signed main()
{
// ios::sync_with_stdio(0);
// freopen("1.in","r",stdin);
// freopen("1.out","w",stdout);
double st=clock();
WrongAnswer_90::Mian();
double ed=clock();
cerr<<endl;
cerr<<"Time: "<<ed-st<<" ms\n";
cerr<<"Memory: "<<abs(&ST-&ED)/1024.0/1024.0<<" MB\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 1
Accepted
Test #1:
score: 1
Accepted
time: 169ms
memory: 6144kb
input:
30 2000 1 9 19 58 20 17 5 20 17 96 27 20 2 15 28 71 14 18 20 19 24 29 18 13 66 21 17 62 20 17 86 23 20 58 18 26 69 29 18 73 30 26 13 27 17 73 23 15 30 10 8 68 25 6 51 7 4 55 23 13 74 12 8 94 23 29 33 6 8 86 1 8 75 14 30 73 23 27 82 14 26 85 12 28 68 1 27 21 6 8 74 22 13 61 17 5 58 28 3 69 1 25 59 11...
output:
1
result:
ok single line: '1'
Test #2:
score: 1
Accepted
time: 151ms
memory: 6620kb
input:
3000 10000 1 2941 1762 34 1456 1466 41 1279 2756 45 396 2841 46 579 12 78 2654 888 18 1656 237 58 1820 2775 80 426 165 3 994 1141 92 1617 1851 28 2449 2082 75 1438 2206 34 2657 774 78 942 1156 40 2329 176 92 858 2172 84 1161 2798 72 982 435 43 1674 1274 88 2827 979 9 1003 1165 50 907 774 81 1142 204...
output:
1
result:
ok single line: '1'
Subtask #2:
score: 0
Wrong Answer
Test #3:
score: 0
Wrong Answer
time: 104ms
memory: 8052kb
input:
5 8 2 1 5 0 4 1 0 5 4 0 3 2 2 2 2 2 4 5 2 4 3 0 1 1 0
output:
1
result:
wrong answer 1st lines differ - expected: '2', found: '1'
Subtask #3:
score: 0
Wrong Answer
Test #6:
score: 0
Wrong Answer
time: 148ms
memory: 15116kb
input:
5000 5259 3 1 8 5 8 7 1 7 9 5 9 4 2 4 5 4 5 3 1 3 2 2 2 6 1 6 10 3 10 1 4 5 11 46 11 5 38 2 14 14 14 13 22 13 15 12 15 12 14 12 16 21 16 2 15 7 26 0 26 28 2 28 25 1 25 23 2 23 20 4 20 24 1 24 22 1 22 21 1 21 27 3 27 30 0 30 19 4 19 18 3 18 17 3 17 29 2 29 7 1 14 33 12 33 31 13 31 36 11 36 34 5 34 38...
output:
1
result:
wrong answer 1st lines differ - expected: '14', found: '1'
Subtask #4:
score: 0
Skipped
Dependency #3:
0%
Subtask #5:
score: 0
Wrong Answer
Test #11:
score: 19
Accepted
time: 57ms
memory: 8536kb
input:
767 10000 5 2 3 1 3 4 1 4 5 1 5 6 1 6 7 1 7 8 1 8 9 1 9 10 1 10 11 1 11 12 1 12 2 1 13 14 1 14 15 1 15 16 1 16 17 1 17 18 1 18 19 1 19 20 1 20 21 1 21 22 1 22 23 1 23 24 1 24 25 1 25 13 1 26 27 1 27 28 1 28 29 1 29 30 1 30 31 1 31 32 1 32 33 1 33 34 1 34 35 1 35 36 1 36 37 1 37 38 1 38 39 1 39 40 1 ...
output:
1
result:
ok single line: '1'
Test #12:
score: 0
Wrong Answer
time: 108ms
memory: 6152kb
input:
26 638 5 1 2 0 2 2 72 2 26 0 2 26 1 2 26 6 2 26 7 2 26 12 2 26 13 2 26 18 2 26 19 2 26 24 2 26 25 2 26 30 2 26 31 2 26 36 2 26 37 2 26 42 2 26 43 2 26 48 2 26 49 2 26 54 2 26 55 2 26 60 2 26 61 2 26 66 2 26 67 1 3 0 3 3 25 3 26 0 3 26 1 3 26 2 3 26 3 3 26 5 3 26 6 3 26 7 3 26 8 3 26 10 3 26 11 3 26 ...
output:
1
result:
wrong answer 1st lines differ - expected: '381798563', found: '1'
Subtask #6:
score: 0
Wrong Answer
Test #16:
score: 0
Wrong Answer
time: 113ms
memory: 8228kb
input:
25 596 6 1 2 0 2 2 16 2 25 2 2 25 4 2 25 5 2 25 6 2 25 7 2 25 8 2 25 9 2 25 10 2 25 11 2 25 12 2 25 13 2 25 14 1 3 0 3 3 64 3 25 0 3 25 1 3 25 2 3 25 6 3 25 7 3 25 8 3 25 9 3 25 10 3 25 14 3 25 15 3 25 16 3 25 17 3 25 18 3 25 22 3 25 23 3 25 24 3 25 25 3 25 26 3 25 30 3 25 31 3 25 32 3 25 33 3 25 34...
output:
1
result:
wrong answer 1st lines differ - expected: '7398268', found: '1'
Subtask #7:
score: 0
Wrong Answer
Test #21:
score: 18
Accepted
time: 57ms
memory: 6268kb
input:
15 133 7 1 2 0 2 2 5 2 15 1 2 15 3 2 15 4 1 3 0 3 3 8 3 15 2 3 15 3 3 15 6 1 4 0 4 4 9 4 15 3 4 15 4 4 15 5 4 15 7 1 5 0 5 5 10 5 15 2 5 15 4 5 15 6 5 15 7 5 15 8 5 15 9 1 6 0 6 6 12 6 15 2 6 15 4 6 15 5 6 15 9 6 15 10 6 15 11 1 7 0 7 7 13 7 15 0 7 15 1 7 15 2 7 15 3 7 15 5 7 15 6 7 15 7 7 15 9 7 15...
output:
1
result:
ok single line: '1'
Test #22:
score: 0
Wrong Answer
time: 58ms
memory: 6088kb
input:
15 123 7 1 2 0 2 2 5 2 15 0 2 15 3 2 15 4 1 3 0 3 3 6 3 15 0 3 15 3 3 15 5 1 4 0 4 4 7 4 15 1 4 15 2 4 15 4 4 15 6 1 5 0 5 5 9 5 15 0 5 15 1 5 15 2 5 15 5 5 15 6 5 15 8 1 6 0 6 6 10 6 15 1 6 15 3 6 15 4 6 15 5 6 15 8 6 15 9 1 7 0 7 7 13 7 15 0 7 15 2 7 15 12 1 8 0 8 8 15 8 15 0 8 15 1 8 15 2 8 15 3 ...
output:
1
result:
wrong answer 1st lines differ - expected: '3063060', found: '1'
Subtask #8:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%