QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#645873 | #6613. Bitwise Exclusive-OR Sequence | wzxtsl# | WA | 0ms | 3668kb | C++23 | 1.6kb | 2024-10-16 20:18:02 | 2024-10-16 20:18:02 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define int long long
#define For(i,a,aa) for(int i=a;i<=aa;i++)
const int N=2e6+7;
int n,m,x,y,w;
int d[N][40];
int yi[40],lin[40];
int p[40];
void solve(){
int ans=0;
cin>>n>>m;
For(i,1,n)
For(j,1,30)
d[i][j]=-1;
For(i,1,m)
{
cin>>x>>y>>w;
int a[40],tot=0;
memset(a,0,sizeof(a));
while(w)
{
a[++tot]=w%2;
w>>=1;
}
For(j,tot+1,30) a[j]=0;
For(j,1,30)
{
if(d[x][j]!=-1&&d[y][j]!=-1)
{
if(d[x][j]^d[y][j]!=a[j])
{
cout<<-1;return;
}
}
else if(d[y][j]==-1&&d[x][j]==-1)
{
d[y][j]=0;
d[x][j]=d[y][j]^a[j];
}
else if(d[x][j]==-1)
{
d[x][j]=d[y][j]^a[j];
}
else{
d[y][j]=d[x][j]^a[j];
}
}
}
For(j,1,30)
{
For(i,1,n)
{
if(d[i][j]==1) yi[j]++;
else if(d[i][j]==0) lin[j]++;//cout<<i<<"!"<<j<<"!!"<<d[i][j]<<endl;
}//cout<<yi[j]<<"!"<<lin[j]<<"!!"<<endl;
ans+=p[j]*min(yi[j],lin[j]);//cout<<ans<<"!";
}
cout<<ans;
}
signed main(){
fast;
int t=1;
//cin>>t;
p[1]=1;
For(i,2,30)
p[i]=p[i-1]*2;
while(t--){
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3668kb
input:
3 2 1 2 1 2 3 1
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3588kb
input:
3 3 1 2 1 2 3 1 1 3 1
output:
-1
result:
ok 1 number(s): "-1"
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3588kb
input:
5 5 3 4 12 3 1 20 2 5 16 1 4 24 4 5 19
output:
-1
result:
wrong answer 1st numbers differ - expected: '58', found: '-1'