Submission #52475663
Source Code Expand
#include<bits/stdc++.h>
#define Gc() getchar()
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define eb emplace_back
#define all(x) x.begin(),x.end()
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;
const int N=300+5,M=2000+5,K=1000+5,mod=998244353,Mod=mod-1;const db eps=1e-8;const int INF=1e9+7;mt19937 rnd(181766);
#define Tp template<typename T>
#define Ts template<typename T,typename... Ar>
namespace Debug{
Tp void _debug(char* f,T t){cerr<<f<<'='<<t<<endl;}
Ts void _debug(char* f,T x,Ar... y){while(*f!=',') cerr<<*f++;cerr<<'='<<x<<",";_debug(f+1,y...);}
#ifdef LOCAL
#define gdb(...) _debug((char*)#__VA_ARGS__,__VA_ARGS__)
#else
#define gdb(...) void()
#endif
}using namespace Debug;
using LL=__int128;
pair<ll,ll> A[3];
vector<ll> pr;
int cnt[3];
LL ans;ll m;
vector<pair<ll,ll> > e[3];
ll qry(ll x,ll k,ll p){
if(x<0) return 0;
return min(k%p,x%p+1)+(k%p)*(x/p);
}
void dfs(int x,LL w){
if(x==2){
for(auto i:e[x]) ans+=A[x].fi/A[x].se*w*(i.se-i.fi+1);
for(auto i:e[x]) ans+=(qry(i.se,A[x].fi,A[x].se)-qry(i.fi-1,A[x].fi,A[x].se))*w;
return;
}
e[x+1]=e[x];dfs(x+1,A[x].fi/A[x].se*w);
e[x+1].clear();
for(auto i:e[x]){
if(i.fi%A[x].se>A[x].fi%A[x].se) i.fi=(i.fi/A[x].se+1)*A[x].se;
while(i.fi/A[x].se<i.se/A[x].se) e[x+1].emplace_back(i.fi,i.fi/A[x].se*A[x].se+A[x].fi%A[x].se-1),i.fi=(i.fi/A[x].se+1)*A[x].se;
if(i.fi<=i.se) e[x+1].emplace_back(i.fi,min(i.se,i.se/A[x].se*A[x].se+A[x].fi%A[x].se-1));
}
dfs(x+1,w);
}
void Solve(){
int i,j;for(int i:{0,1,2}) scanf("%lld%lld",&A[i].fi,&A[i].se),A[i].se+=A[i].fi;
LL lm=1;for(int i:{0,1,2}) lm*=A[i].se/__gcd(lm,(LL)A[i].se);
lm=(LL)A[0].se*A[1].se*A[2].se/lm;
for(int i:{0,1,2}){
ll x=A[i].se;
for(int j=2;1ll*j*j<=x;j++) if(x%j==0){
pr.emplace_back(j);while(x%j==0) x/=j;
}
if(x^1) pr.emplace_back(x);
}
for(ll p:pr){
for(int i:{0,1,2}) {
ll x=A[i].se;cnt[i]=0;
while(x%p==0) cnt[i]++,x/=p;
}
int mx=*max_element(cnt,cnt+3),k=mx-(accumulate(cnt,cnt+3,0)-mx-*min_element(cnt,cnt+3));
ll pw=1;while(k--) pw*=p;
for(int i:{0,1,2}) if(cnt[i]==mx) A[i].se/=pw;
}
m=1;for(int i:{0,1,2}) m*=A[i].se/__gcd(A[i].se,m),gdb(A[i].se);
sort(A,A+3,[](pair<ll,ll> x,pair<ll,ll> y){return x.se>y.se;});
e[0].emplace_back(0,m-1);
dfs(0,1);
/*for(ll i=0;i<m;i++){
LL mul=1;for(int j:{0,1,2}) mul*=(A[j].fi/A[j].se+(i%A[j].se<A[j].fi%A[j].se));
ans+=mul;gdb((ll)mul);
}*/
printf("%lld\n",ll(ans*lm%mod));
}
int main(){
int t=1;
// scanf("%d",&t);
while(t--) Solve();
cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}
Submission Info
| Submission Time |
|
| Task |
E - Three Traffic Lights |
| User |
fangxintong |
| Language |
C++ 20 (gcc 12.2) |
| Score |
1800 |
| Code Size |
2906 Byte |
| Status |
AC |
| Exec Time |
84 ms |
| Memory |
50852 KiB |
Compile Error
Main.cpp: In function ‘void Solve()’:
Main.cpp:53:13: warning: unused variable ‘i’ [-Wunused-variable]
53 | int i,j;for(int i:{0,1,2}) scanf("%lld%lld",&A[i].fi,&A[i].se),A[i].se+=A[i].fi;
| ^
Main.cpp:53:15: warning: unused variable ‘j’ [-Wunused-variable]
53 | int i,j;for(int i:{0,1,2}) scanf("%lld%lld",&A[i].fi,&A[i].se),A[i].se+=A[i].fi;
| ^
Main.cpp:53:41: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
53 | int i,j;for(int i:{0,1,2}) scanf("%lld%lld",&A[i].fi,&A[i].se),A[i].se+=A[i].fi;
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
1800 / 1800 |
| Status |
|
|
| Set Name |
Test Cases |
| Sample |
example0.txt, example1.txt, example2.txt |
| All |
000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, 025.txt, 026.txt, 027.txt, 028.txt, 029.txt, 030.txt, 031.txt, 032.txt, 033.txt, 034.txt, 035.txt, 036.txt, 037.txt, 038.txt, 039.txt, 040.txt, 041.txt, 042.txt, 043.txt, 044.txt, 045.txt, 046.txt, 047.txt, 048.txt, 049.txt, 050.txt, 051.txt, 052.txt, 053.txt, 054.txt, 055.txt, 056.txt, 057.txt, 058.txt, 059.txt, 060.txt, 061.txt, 062.txt, 063.txt, 064.txt, 065.txt, 066.txt, 067.txt, 068.txt, 069.txt, 070.txt, 071.txt, 072.txt, 073.txt, 074.txt, 075.txt, 076.txt, 077.txt, 078.txt, 079.txt, 080.txt, 081.txt, 082.txt, 083.txt, 084.txt, 085.txt, 086.txt, 087.txt, 088.txt, 089.txt, 090.txt, 091.txt, 092.txt, 093.txt, example0.txt, example1.txt, example2.txt |
| Case Name |
Status |
Exec Time |
Memory |
| 000.txt |
AC |
1 ms |
3740 KiB |
| 001.txt |
AC |
1 ms |
4020 KiB |
| 002.txt |
AC |
1 ms |
3980 KiB |
| 003.txt |
AC |
1 ms |
3920 KiB |
| 004.txt |
AC |
1 ms |
3920 KiB |
| 005.txt |
AC |
1 ms |
3884 KiB |
| 006.txt |
AC |
1 ms |
3748 KiB |
| 007.txt |
AC |
1 ms |
3976 KiB |
| 008.txt |
AC |
1 ms |
4028 KiB |
| 009.txt |
AC |
1 ms |
3996 KiB |
| 010.txt |
AC |
1 ms |
4052 KiB |
| 011.txt |
AC |
1 ms |
4104 KiB |
| 012.txt |
AC |
2 ms |
4044 KiB |
| 013.txt |
AC |
1 ms |
3972 KiB |
| 014.txt |
AC |
1 ms |
4104 KiB |
| 015.txt |
AC |
1 ms |
4156 KiB |
| 016.txt |
AC |
1 ms |
3828 KiB |
| 017.txt |
AC |
2 ms |
4040 KiB |
| 018.txt |
AC |
1 ms |
3728 KiB |
| 019.txt |
AC |
1 ms |
4044 KiB |
| 020.txt |
AC |
17 ms |
12456 KiB |
| 021.txt |
AC |
67 ms |
42456 KiB |
| 022.txt |
AC |
1 ms |
3804 KiB |
| 023.txt |
AC |
2 ms |
4304 KiB |
| 024.txt |
AC |
18 ms |
13220 KiB |
| 025.txt |
AC |
65 ms |
42728 KiB |
| 026.txt |
AC |
81 ms |
50352 KiB |
| 027.txt |
AC |
69 ms |
43204 KiB |
| 028.txt |
AC |
84 ms |
50852 KiB |
| 029.txt |
AC |
82 ms |
50408 KiB |
| 030.txt |
AC |
1 ms |
3932 KiB |
| 031.txt |
AC |
2 ms |
3972 KiB |
| 032.txt |
AC |
1 ms |
4004 KiB |
| 033.txt |
AC |
1 ms |
3948 KiB |
| 034.txt |
AC |
1 ms |
3848 KiB |
| 035.txt |
AC |
1 ms |
3752 KiB |
| 036.txt |
AC |
2 ms |
4160 KiB |
| 037.txt |
AC |
1 ms |
4044 KiB |
| 038.txt |
AC |
8 ms |
7468 KiB |
| 039.txt |
AC |
1 ms |
3916 KiB |
| 040.txt |
AC |
1 ms |
4028 KiB |
| 041.txt |
AC |
1 ms |
3848 KiB |
| 042.txt |
AC |
2 ms |
4064 KiB |
| 043.txt |
AC |
2 ms |
3896 KiB |
| 044.txt |
AC |
1 ms |
3976 KiB |
| 045.txt |
AC |
1 ms |
3740 KiB |
| 046.txt |
AC |
1 ms |
4104 KiB |
| 047.txt |
AC |
1 ms |
3724 KiB |
| 048.txt |
AC |
1 ms |
3924 KiB |
| 049.txt |
AC |
1 ms |
3972 KiB |
| 050.txt |
AC |
6 ms |
5352 KiB |
| 051.txt |
AC |
1 ms |
4008 KiB |
| 052.txt |
AC |
1 ms |
4164 KiB |
| 053.txt |
AC |
1 ms |
3984 KiB |
| 054.txt |
AC |
14 ms |
11664 KiB |
| 055.txt |
AC |
1 ms |
3908 KiB |
| 056.txt |
AC |
1 ms |
3840 KiB |
| 057.txt |
AC |
19 ms |
11668 KiB |
| 058.txt |
AC |
1 ms |
3940 KiB |
| 059.txt |
AC |
1 ms |
3996 KiB |
| 060.txt |
AC |
2 ms |
4124 KiB |
| 061.txt |
AC |
1 ms |
4036 KiB |
| 062.txt |
AC |
16 ms |
11644 KiB |
| 063.txt |
AC |
1 ms |
4032 KiB |
| 064.txt |
AC |
1 ms |
3848 KiB |
| 065.txt |
AC |
1 ms |
3908 KiB |
| 066.txt |
AC |
1 ms |
3828 KiB |
| 067.txt |
AC |
1 ms |
3904 KiB |
| 068.txt |
AC |
1 ms |
3948 KiB |
| 069.txt |
AC |
1 ms |
3868 KiB |
| 070.txt |
AC |
1 ms |
3880 KiB |
| 071.txt |
AC |
2 ms |
4108 KiB |
| 072.txt |
AC |
1 ms |
4036 KiB |
| 073.txt |
AC |
1 ms |
3748 KiB |
| 074.txt |
AC |
1 ms |
3728 KiB |
| 075.txt |
AC |
15 ms |
11656 KiB |
| 076.txt |
AC |
1 ms |
3848 KiB |
| 077.txt |
AC |
1 ms |
3728 KiB |
| 078.txt |
AC |
1 ms |
3924 KiB |
| 079.txt |
AC |
1 ms |
4072 KiB |
| 080.txt |
AC |
1 ms |
3980 KiB |
| 081.txt |
AC |
1 ms |
3912 KiB |
| 082.txt |
AC |
2 ms |
3980 KiB |
| 083.txt |
AC |
1 ms |
3908 KiB |
| 084.txt |
AC |
1 ms |
3824 KiB |
| 085.txt |
AC |
10 ms |
3964 KiB |
| 086.txt |
AC |
9 ms |
3904 KiB |
| 087.txt |
AC |
9 ms |
3888 KiB |
| 088.txt |
AC |
3 ms |
3904 KiB |
| 089.txt |
AC |
3 ms |
3980 KiB |
| 090.txt |
AC |
3 ms |
3980 KiB |
| 091.txt |
AC |
39 ms |
24936 KiB |
| 092.txt |
AC |
35 ms |
23380 KiB |
| 093.txt |
AC |
37 ms |
25360 KiB |
| example0.txt |
AC |
1 ms |
3980 KiB |
| example1.txt |
AC |
1 ms |
3908 KiB |
| example2.txt |
AC |
3 ms |
3912 KiB |