제출 #381497

#제출 시각아이디문제언어결과실행 시간메모리
381497kartelPaint (COI20_paint)C++14
8 / 100
1022 ms1900 KiB
#include <bits/stdc++.h> #define in(x) freopen(x, "r", stdin) #define out(x) freopen(x, "w", stdout) //#include <time.h> //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> //#pragma GCC optimize("Ofast") //#pragma GCC optimize("unroll-loops") //#pragma GCC optimize("-O3") #define F first #define S second #define pb push_back #define M ll(1e9 + 7) //#define M ll(998244353) #define sz(x) (int)x.size() #define re return #define oo ll(1e18) #define el '\n' #define pii pair <int, int> #define all(x) (x).begin(), (x).end() #define arr_all(x, n) (x + 1), (x + 1 + n) #define vi vector<int> #define eps (ld)1e-9 using namespace std; typedef long long ll; //using namespace __gnu_pbds; //typedef tree <ll, null_type, less_equal <ll> , rb_tree_tag, tree_order_statistics_node_update> ordered_set; typedef double ld; typedef unsigned long long ull; typedef short int si; int steps[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}}; int n, m, qq; vector < vector <int> > a, mk; //int id(int i, int j) {return (i * m + j);} // //int f(int x) {return (x == pr[x] ? x : pr[x] = f(pr[x]));} //void link(int x, int y) { // x = f(x); // y = f(y); // // if (x == y) { // return; // } // // if (siz[x] > siz[y]) { // swap(x, y); // } // // pr[x] = y; // siz[y] += siz[x]; //} void solve() { queue <pii> q; while (qq--) { int i, j, c; cin >> i >> j >> c; i--; j--; q.push({i, j}); int old = a[i][j]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { mk[i][j] = 0; } } while (sz(q)) { int x = q.front().F; int y = q.front().S; q.pop(); a[x][y] = c; for (int i = 0; i < 4; i++) { int cx = x + steps[i][0]; int cy = y + steps[i][1]; if (cx < 0 || cy < 0 || cx >= n || cy >= m || a[cx][cy] != old || mk[cx][cy]) { continue; } mk[cx][cy] = 1; q.push({cx, cy}); } } } for (int i = 0; i < n; i++, cout << el) { for (int j = 0; j < m; j++) { cout << a[i][j] << " "; } } } int main() { // mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());; ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); // in("toys.in"); // out("toys.out"); // in("input.txt"); // out("output.txt"); // cerr.precision(9); cerr << fixed; // clock_t tStart = clock(); cin >> n >> m; a.resize(n); mk.resize(n); for (int i = 0; i < n; i++) { a[i].resize(m); mk[i].resize(m); for (int j = 0; j < m; j++) { cin >> a[i][j]; // pr[id(i, j)] = id(i, j); // siz[id(i, j)] = 1; } } cin >> qq; if (n > 1 && n * m * 1ll * qq <= 100000000) { solve(); } // for (int i = 0; i < n; i++) { // for (int j = 0; j < m; j++) { // for (int k = 0; k < 4; k++) { // int x = i + steps[k][0]; // int y = j + steps[k][1]; // // if (x < 0 || y < 0 || x >= n || y >= m || a[x][y] != a[i][j]) { // continue; // } // // link(id(i, j), id(x, y)); // } // } // } // // for (int i = 0; i < n; i++) { // for (int j = 0; j < m; j++) { // for (int k = 0; k < 4; k++) { // int x = i + steps[k][0]; // int y = j + steps[k][1]; // // if (x < 0 || y < 0 || x >= n || y >= m || a[x][y] == a[i][j]) { // continue; // } // // ng[f(id(i, j))][a[x][y]].insert(f(id(x, y))); // } // } // } // // while (qq--) { // int x, y, c; // cin >> x >> y >> c; x--; y--; // // if (n == 1) { // upd(id(x, y), c); // } // } } /* 7 4 6 7 2 3 1 5 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...