CSAcademy Square Cover
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0)
#define bfast cin.tie(0)
#define outs(x) cout << x << " "
#define outn(x) cout << x << "\n"
#define sf scanf
#define pf printf
#define pfn(x , k) printf(k , x)
#define nl puts("")
#define psb push_back
#define mset(c,v) memset(c , v , sizeof c)
#define loop0(n) for(int i=0; i<n; i++)
#define loop1(n) for(int i=1; i<=n; i++)
#define mpair(x , y) make_pair(x , y)
#define all(x) x.begin(), x.end()
#define pi acos(-1.0)
#define psb push_back
#define clr clear()
typedef unsigned long long ull;
typedef long long LL;
typedef vector<int>vii;
typedef vector<LL>vll;
typedef vector<string>vs;
typedef map<int, int>mpii;
typedef map<string, int>mpsi;
typedef map<char, int>mpci;
typedef map<LL, LL>mpll;
typedef map<pair<int, int> , bool >mppbl;
const int mod = 1000007;
const int high = 300+5;
int matrix[high][high];
int visited[100003];
int main()
{
fast;
int x , i , j , row , col , k , l , m , limit;
while(cin >> row >> col)
{
for(i=0; i<row; i++)
{
for(j=0; j<col; j++)
{
cin >> x;
matrix[i][j] = x;
visited[x] = 0;
}
} //outn("\n");
bool fl=false;
for(i=0; i<row; i++)
{
for(j=0; j<col; j++)
{
x = matrix[i][j];
if(x == -1) continue;
if(!visited[x])
{
visited[x] = 1;
limit = row - i;
for(k=i; k<row; k++)
{
if(matrix[k][j] != x)
{
limit = k - i;
break;
}
}
for(l=i; l<limit+i; l++)
{
for(m=j; m<limit+j; m++)
{
if(matrix[l][m] != x)
{
fl=true;
break;
}
matrix[l][m] = -1;
}
if(fl) break;
}
}
else
{
fl=true;
break;
}
}
if(fl) break;
}
if(fl) cout << "0\n";
else cout << "1\n";
}
return 0;
}
using namespace std;
#define fast ios_base::sync_with_stdio(0)
#define bfast cin.tie(0)
#define outs(x) cout << x << " "
#define outn(x) cout << x << "\n"
#define sf scanf
#define pf printf
#define pfn(x , k) printf(k , x)
#define nl puts("")
#define psb push_back
#define mset(c,v) memset(c , v , sizeof c)
#define loop0(n) for(int i=0; i<n; i++)
#define loop1(n) for(int i=1; i<=n; i++)
#define mpair(x , y) make_pair(x , y)
#define all(x) x.begin(), x.end()
#define pi acos(-1.0)
#define psb push_back
#define clr clear()
typedef unsigned long long ull;
typedef long long LL;
typedef vector<int>vii;
typedef vector<LL>vll;
typedef vector<string>vs;
typedef map<int, int>mpii;
typedef map<string, int>mpsi;
typedef map<char, int>mpci;
typedef map<LL, LL>mpll;
typedef map<pair<int, int> , bool >mppbl;
const int mod = 1000007;
const int high = 300+5;
int matrix[high][high];
int visited[100003];
int main()
{
fast;
int x , i , j , row , col , k , l , m , limit;
while(cin >> row >> col)
{
for(i=0; i<row; i++)
{
for(j=0; j<col; j++)
{
cin >> x;
matrix[i][j] = x;
visited[x] = 0;
}
} //outn("\n");
bool fl=false;
for(i=0; i<row; i++)
{
for(j=0; j<col; j++)
{
x = matrix[i][j];
if(x == -1) continue;
if(!visited[x])
{
visited[x] = 1;
limit = row - i;
for(k=i; k<row; k++)
{
if(matrix[k][j] != x)
{
limit = k - i;
break;
}
}
for(l=i; l<limit+i; l++)
{
for(m=j; m<limit+j; m++)
{
if(matrix[l][m] != x)
{
fl=true;
break;
}
matrix[l][m] = -1;
}
if(fl) break;
}
}
else
{
fl=true;
break;
}
}
if(fl) break;
}
if(fl) cout << "0\n";
else cout << "1\n";
}
return 0;
}
Comments
Post a Comment