QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#480906 | #905. 三元环枚举 | 275307894a# | WA | 15ms | 9916kb | C++14 | 1.8kb | 2024-07-16 19:31:53 | 2024-07-16 19:31:54 |
Judging History
answer
#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 ll;using pii=pair<int,int>;
const int N=1e5+5,M=N*30+5,K=1000+5,mod=998244353,Mod=mod-1;const db eps=1e-9;const ll INF=1e18+7;mt19937 rnd(time(0));
#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;
int n,m,rk[N],id[N],A[N],X[N],Y[N],in[N];
vector<int> S[N];
void Solve(){
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++) scanf("%d",&A[i]);
for(int i=1;i<=m;i++){
scanf("%d%d",&X[i],&Y[i]);
X[i]++;Y[i]++;
in[X[i]]++;in[Y[i]]++;
}
iota(id+1,id+n+1,1);
sort(id+1,id+n+1,[](int x,int y){return in[x]<in[y];});
for(int i=1;i<=n;i++) rk[id[i]]=i;
for(int i=1;i<=m;i++){
if(rk[X[i]]>rk[Y[i]]) swap(X[i],Y[i]);
S[X[i]].push_back(Y[i]);
}
ll ans=0;
for(int i=1;i<=n;i++){
static int ap[N];
for(int j:S[i]) ap[j]=1;
for(int j:S[i]) for(int h:S[j]) if(ap[h]) ans+=A[i]*A[j]%mod*A[h]%mod;
for(int j:S[i]) ap[j]=0;
}
printf("%lld\n",ans%mod);
}
int main(){
int t=1;
// scanf("%d",&t);
while(t--) Solve();
cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 8972kb
input:
4 5 1 2 3 4 0 3 2 0 2 1 2 3 1 3
output:
36
result:
ok "36"
Test #2:
score: -100
Wrong Answer
time: 15ms
memory: 9916kb
input:
17707 77101 528756313 434883274 318065816 264440383 659789617 608119380 648104885 725454492 696703871 543030428 663661240 890791532 108201616 428505484 322953840 119811886 691103780 306647414 549862302 176916719 909058872 455464665 307270851 584469329 722629343 875317523 629938577 244419357 78121457...
output:
-170875399
result:
wrong answer 1st words differ - expected: '397965084', found: '-170875399'