QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#462784 | #8830. Breaking Bad | ucup-team2307 | WA | 0ms | 3664kb | C++20 | 3.7kb | 2024-07-04 04:10:48 | 2024-07-04 04:10:48 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
using pii = pair<int, int>;
using vi = vector<int>;
#define fi first
#define se second
#define pb push_back
int n;
int a[1010][1010];
pair<int, int> fnd(int l)
{
for (int i=l; i<n; i++)
for (int j=l; j<n; j++)
if (a[l][l] + a[i][j] != a[i][l] + a[l][j])
return {i, j};
return {-1, -1};
}
void sw1(int i, int j)
{
for (int k=0; k<n; k++)
swap(a[i][k], a[j][k]);
}
void sw2(int i, int j)
{
for (int k=0; k<n; k++)
swap(a[k][i], a[k][j]);
}
int addmask(int m, int i)
{
m = (m<<i) | (m>>(5-i));
m &= 31;
return m;
}
void upd(vector<int>& cur, vector<int> v)
{
auto nt = cur;
int k = v.size();
for (int i=0; i<k; i++)
for (int j=0; j<(1<<k); j++)
if (((j>>i)&1)==0)
nt[j|(1<<i)] |= addmask(cur[j], v[i]);
cur = nt;
}
signed main() {
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(cin.failbit);
cin>>n;
for (int i=0; i<n; i++)
for (int j=0; j<n; j++)
cin>>a[i][j];
int l = 0;
while (true)
{
if (l >= 10)
{
cout<<"YYYYY\n";
return 0;
}
auto pa = fnd(l);
if (pa.fi == -1)
break;
sw1(l+1, pa.fi);
sw2(l+1, pa.se);
l+=2;
}
int s = 0;
for (int i=l; i<=n; i++)
{
int w = a[l][i];
for (int j=0; j<n; j++)
a[j][i] = (a[j][i] + 5 - w) % 5;
s += w;
}
for (int i=l; i<=n; i++)
{
int w = a[i][l];
for (int j=0; j<n; j++)
a[i][j] = (a[i][j] + 5 - w) % 5;
s += w;
}
vector<int> rm(1<<l), cm(1<<l);
rm[0] = 1;
cm[0] = 1;
for (int i=l; i<n; i++)
{
vector<int> nt;
for (int j=0; j<l; j++)
nt.pb(a[i][j]);
upd(rm, nt);
nt.clear();
for (int j=0; j<l; j++)
nt.pb(a[j][i]);
upd(cm, nt);
}
// cout<<s<<" "<<l<<"\n";
// for (int i=0; i<n; i++, cout<<"\n")
// for (int j=0; j<n; j++)
// cout<<a[i][j]<<" ";
// for (int i=0; i<(1<<l); i++)
// cout<<rm[i]<<" ";
// cout<<"\n";
// for (int i=0; i<(1<<l); i++)
// cout<<cm[i]<<" ";
// cout<<endl;
vector<int> ok(5);
for (int mask1=0; mask1<(1<<l); mask1++)
for (int mask2=0; mask2<(1<<l); mask2++)
if (__builtin_popcount(mask1) == __builtin_popcount(mask2))
{
vector<int> x, y;
for (int i=0; i<l; i++)
if ((mask1>>i)&1)
x.pb(i);
for (int i=0; i<l; i++)
if ((mask2>>i)&1)
y.pb(i);
int k = x.size();
// cout<<mask1<<" "<<mask2<<" "<<x.size()<<" "<<y.size()<<endl;
vector<int> p;
for (int i=0; i<k; i++)
p.pb(i);
while (true)
{
int sm = s;
for (int i=0; i<k; i++)
sm += a[y[i]][x[p[i]]];
int d1 = rm[mask1^((1<<l)-1)];
int d2 = cm[mask2^((1<<l)-1)];
// cout<<mask1<<" "<<mask2<<" "<<d1<<" "<<d2<<" "<<sm<<endl;
for (int i=0; i<5; i++)
if ((d1>>i)&1)
for (int j=0; j<5; j++)
if ((d2>>j)&1)
ok[(sm+i+j)%5] = 1;
if (!next_permutation(p.begin(), p.end()))
break;
}
}
for (int i=0; i<5; i++)
cout<<"NY"[ok[i]];
cout<<"\n";
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3556kb
input:
2 0 4 4 0
output:
YNNYN
result:
ok "YNNYN"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3524kb
input:
2 1 1 1 1
output:
NNYNN
result:
ok "NNYNN"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3596kb
input:
4 0 0 1 0 0 1 0 1 0 0 0 0 1 1 0 0
output:
YYYYN
result:
ok "YYYYN"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3580kb
input:
4 0 0 0 1 0 1 0 1 1 0 0 0 0 1 0 0
output:
YYYYN
result:
ok "YYYYN"
Test #5:
score: -100
Wrong Answer
time: 0ms
memory: 3664kb
input:
10 1 4 2 0 0 2 0 1 3 3 0 3 1 4 4 1 4 0 2 2 1 4 2 0 0 2 0 1 0 3 0 3 1 4 4 1 4 0 2 2 4 2 0 3 3 0 3 4 1 1 2 0 3 1 1 3 1 2 4 4 4 2 0 3 3 0 3 4 1 1 2 0 3 1 1 3 1 2 4 4 1 4 2 0 0 2 0 1 3 3 3 1 4 2 2 4 2 3 0 0
output:
YYYYY
result:
wrong answer 1st words differ - expected: 'NYNNY', found: 'YYYYY'