[ARC140E] Not Equal Rectangle
Genius_Star · · 题解
比较牛的题,场切了。
思路:
容易发现,我只要构造出一个很大的满足条件的矩阵,随便取中间一个
看到构造先打表,先打方阵的表,场上瞪了半小时,发现
于是想到用这个
考虑用
整理一下可以得到:
想要使得不存在
那么设
因为显然
于是取
完整代码:
#include<bits/stdc++.h>
#define lowbit(x) x & (-x)
#define ls(k) k << 1
#define rs(k) k << 1 | 1
#define fi first
#define se second
#define ctz(x) __builtin_ctz(x)
#define popcnt(x) __builtin_popcount(x)
#define open(s1, s2) freopen(s1, "r", stdin), freopen(s2, "w", stdout);
using namespace std;
typedef __int128 __;
typedef long double lb;
typedef double db;
typedef unsigned long long ull;
typedef long long ll;
const int N = 505, M = 1e6 + 10;
inline ll read(){
ll x = 0, f = 1;
char c = getchar();
while(c < '0' || c > '9'){
if(c == '-')
f = -1;
c = getchar();
}
while(c >= '0' && c <= '9'){
x = (x << 1) + (x << 3) + (c ^ 48);
c = getchar();
}
return x * f;
}
inline void write(ll x){
if(x < 0){
putchar('-');
x = -x;
}
if(x > 9)
write(x / 10);
putchar(x % 10 + '0');
}
mt19937 R(time(0));
int n, m, mod = 23;
int A[M];
inline int id(int i, int j){
return i * m + j;
}
inline bool check(){
for(int x1 = 0; x1 < n; ++x1){
for(int x2 = x1 + 1; x2 < n; ++x2){
for(int y1 = 0; y1 < m; ++y1){
for(int y2 = y1 + 1; y2 < m; ++y2){
if(A[id(x1, y1)] == A[id(x1, y2)] && A[id(x1, y2)] == A[id(x2, y1)] && A[id(x2, y1)] == A[id(x2, y2)])
return 0;
}
}
}
}
return 1;
}
int main(){
n = read(), m = read();
for(int i = 0; i < n; ++i){
for(int j = 0; j < m; ++j){
A[id(i, j)] = (i + j + (i / mod) * (j / mod)) % mod + 1;
write(A[id(i, j)]);
putchar(' ');
}
putchar('\n');
}
// if(check())
// puts("Yes");
// else
// puts("No");
return 0;
}