Engineer Artem

Engineer Artem

Created by LXC on Tue Apr 30 14:01:31 2024

https://codeforces.com/problemset/problem/1438/C

ranting: 2000

tag: 2-sat, chinese remainder theorem, constructive algorithms, fft, flows

problem

给出一个 $n\times m$ 的矩阵 $a$($1\le n,m\le 100$),其中 $1\le a_{i,j}\le 10^9$。

定义一个矩阵是合法的当且仅当没有任何两个相邻的元素是相等的(上下左右为相邻)。

你可以将矩阵中若干个元素加一,使其合法,输出最终矩阵。

形式化地,对于每个 $(i,j)$,$b_{i,j}=a_{i,j}$ 或者 $b_{i,j}=a_{i,j}+1$,输出合法的 $b$ 矩阵。

$t$ 组数据($t\le 10$)。

solution

让每个位置与周边的奇偶性不同即可。

code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60

#include <bits/stdc++.h>
// #define SINGLE_INPUT
#define ll long long
#define ull unsigned long long
#define N 500005
#define MOD 998244353
using namespace std;

random_device seed;
ranlux48 engine(seed());
int random(int l, int r) {
uniform_int_distribution<> distrib(l, r);
return distrib(engine);
}
template<class t,class u> ostream& operator<<(ostream& os,const pair<t,u>& p) {
return os<<'['<<p.first<<", "<<p.second<<']';
}
template<class t> ostream& operator<<(ostream& os,const vector<t>& v) {
os<<'['; int s = 1;
for(auto e:v) { if (s) s = 0; else os << ", "; os << e; }
return os<<']';
}
template<class t,class u> ostream& operator<<(ostream& os,const map<t,u>& mp){
os<<'{'; int s = 1;
for(auto [x,y]:mp) { if (s) s = 0; else os << ", "; os<<x<<": "<<y; }
return os<<'}';
}

void sol() {
int n, m;
cin >> n >> m;
for (int i=0; i<n; i++) {
for (int j=0; j<m; j++) {
int x;
cin >> x;
if ((i+j)%2 != x%2) x++;
cout << x << " ";
}
cout << "\n";
}
}

int main() {
cout << setprecision(15) << fixed;
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
#ifndef SINGLE_INPUT
int t;
cin >> t;
while (t--) {
sol();
}
#else
sol();
#endif
return 0;
}