Submission #57229915
Source Code Expand
Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
// LUOGU_RID: 175303068
// Written by da_ke
// Website: https://mahaoming2022.github.io
#include <bits/stdc++.h>
#define i64 long long
#define rep(i,l,r) for(int i=(l);i<=(r);i++)
#define fdn(i,r,l) for(int i=(r);i>=(l);i--)
#define pii pair<int,int>
using namespace std;
typedef long long ll;
typedef double db;
typedef __int128 i128;
const int N=1e3+23;
const int Dx[5]={0,0,-1,1};
const int Dy[5]={1,-1,0,0};
int n,m;
vector<vector<int> > a;
int dp[N][2][2][2],t[3][N];
bool check(int i,int j,int k,int l)
{
// i-2,i-1,i
// 0,1,2
rep(o,1,m)
{
if(i>=3) t[0][o]=a[i-2][o]^l;
else t[0][o]=-1;
}
rep(o,1,m)
t[1][o]=a[i-1][o]^k;
rep(o,1,m)
{
if(i<=n) t[2][o]=a[i][o]^j;
else t[2][o]=-1;
}
rep(o,1,m)
{
bool tag=0;
rep(D,0,3)
{
int x=1+Dx[D],y=o+Dy[D];
if(y<1||y>m||t[x][y]==-1) continue;
if(t[1][o]==t[x][y]) tag=1;
}
if(!tag) return 0;
}
return 1;
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.in","r",stdin);
freopen("out.out","w",stdout);
#endif
ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
cin>>n>>m;
a.resize(n+1);
rep(i,1,n) {a[i].resize(m+1);rep(j,1,m)cin>>a[i][j];}
rep(i,0,n) rep(j,0,1) rep(k,0,1) rep(l,0,1) dp[i][j][k][l]=1<<29;
dp[1][0][0][0]=0,dp[1][1][0][0]=1;
rep(i,2,n) rep(j,0,1) rep(k,0,1) rep(l,0,1)
if(check(i,j,k,l))
dp[i][j][k][l]=min(dp[i][j][k][l],dp[i-1][k][l][0]+j),dp[i][j][k][l]=min(dp[i][j][k][l],dp[i-1][k][l][0]+j);
int ans=1<<29;
rep(i,0,1) rep(j,0,1) rep(k,0,1)
if(check(n+1,0,j,k))
ans=min(ans,dp[n][i][j][k]);
cout<<(ans!=(1<<29)?ans:-1);
}
// hope to debug successfully
Submission Info
Submission Time |
|
Task |
E - Don't Isolate Elements |
User |
da_ke |
Language |
C++ 17 (gcc 12.2) |
Score |
0 |
Code Size |
1863 Byte |
Status |
WA |
Exec Time |
72 ms |
Memory |
6880 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
0 / 500 |
Status |
|
|
Set Name |
Test Cases |
Sample |
example0.txt, example1.txt, example2.txt |
All |
example0.txt, example1.txt, example2.txt, hand0.txt, hand1.txt, hand2.txt, hand3.txt, random0.txt, random1.txt, random10.txt, random11.txt, random12.txt, random13.txt, random14.txt, random15.txt, random16.txt, random17.txt, random18.txt, random19.txt, random2.txt, random20.txt, random21.txt, random22.txt, random3.txt, random4.txt, random5.txt, random6.txt, random7.txt, random8.txt, random9.txt |
Case Name |
Status |
Exec Time |
Memory |
example0.txt |
WA |
1 ms |
3520 KB |
example1.txt |
AC |
1 ms |
3448 KB |
example2.txt |
AC |
1 ms |
3528 KB |
hand0.txt |
WA |
1 ms |
3532 KB |
hand1.txt |
WA |
1 ms |
3528 KB |
hand2.txt |
AC |
1 ms |
3520 KB |
hand3.txt |
WA |
68 ms |
6440 KB |
random0.txt |
AC |
66 ms |
6472 KB |
random1.txt |
AC |
68 ms |
6692 KB |
random10.txt |
WA |
71 ms |
6820 KB |
random11.txt |
WA |
72 ms |
6880 KB |
random12.txt |
WA |
72 ms |
6736 KB |
random13.txt |
AC |
45 ms |
6468 KB |
random14.txt |
AC |
46 ms |
6876 KB |
random15.txt |
AC |
46 ms |
6820 KB |
random16.txt |
AC |
47 ms |
6736 KB |
random17.txt |
AC |
46 ms |
6716 KB |
random18.txt |
AC |
44 ms |
6608 KB |
random19.txt |
AC |
46 ms |
6744 KB |
random2.txt |
AC |
67 ms |
6476 KB |
random20.txt |
AC |
44 ms |
6488 KB |
random21.txt |
AC |
45 ms |
6716 KB |
random22.txt |
AC |
45 ms |
6732 KB |
random3.txt |
WA |
69 ms |
6736 KB |
random4.txt |
WA |
72 ms |
6768 KB |
random5.txt |
WA |
71 ms |
6756 KB |
random6.txt |
WA |
71 ms |
6816 KB |
random7.txt |
WA |
69 ms |
6768 KB |
random8.txt |
WA |
70 ms |
6720 KB |
random9.txt |
WA |
68 ms |
6748 KB |