QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#526108#5573. Holiday RegiftingCaptainflyWA 1ms3592kbC++201.9kb2024-08-21 11:08:282024-08-21 11:08:29

Judging History

你现在查看的是最新测评结果

  • [2024-08-21 11:08:29]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3592kb
  • [2024-08-21 11:08:28]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
#define mp make_pair
#define ull unsigned long long
#define all(x) x.begin(), x.end()
//__builtin_count()
typedef array<int,2> pr;
const unsigned int mask =  (chrono::steady_clock::now().time_since_epoch().count());
inline int gcd(int a, int b){return b == 0 ? a : gcd(b, a % b);}//gcd(a,b)=gcd(a,b-a)(b>a);
inline int lcm(int a, int b){return a / gcd(a, b) * b;}//lcm(n,m)=n*m/gcd(n,m)
const ll mod = 998244353;
const int inv2 = (mod+1)/2;
#define lson rt<<1
#define rson rt<<1|1
int addmod(int &x, int y) {x = (x + y >= mod ? x + y - mod : x + y);return 1;}
ll qpow(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll inv(int x){return qpow(x,mod-2);}
inline void read(__int128 &x)
{
    char c; while(!((c=getchar())>='0'&&c<='9'));
    x=c-'0';
    while((c=getchar())>='0'&&c<='9') (x*=10)+=c-'0';
}
int o[200010],on;
inline void output(__int128 x)
{
    on=0;
    while(x) o[++on]=x%10,x/=10;
    for(int i=on;i>=1;i--) cout<<o[i];
}
#define maxn 200010
int n,m;
vector<int> vec[maxn];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>m;
    vector<int> c(n+1);
    for(int i=1;i<=n;i++)
    {
        cin>>c[i];
    }
    for(int i=1;i<=m;i++)
    {
        int u,v;
        cin>>u>>v;
        vec[u].push_back(v);
    }
    int ans=1;
    vector<ll> a(n+1,0);
    a[1]=1;
    for(int i=1;i<=n;i++)
    {
        int g=c[i]/gcd(1ll*c[i],a[i]);
        ans=1ll*ans*g%mod;
        for(int j=i;j<=n;j++)
        {
            a[j]*=g;
        }
        for(int j=i;j<=n;j++)
        {
            for(auto x:vec[j])
            {
                a[x]+=a[j]/c[j];
                a[j]%=c[j];
            }
        }
    }
    cout<<ans<<'\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3592kb

input:

5 10
4 3 2 2 2
1 3
3 4
1 4
1 5
2 5
2 4
1 2
2 3
3 5
4 5

output:

32

result:

wrong answer 1st numbers differ - expected: '24', found: '32'