답안 #381533

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
381533 2021-03-25T09:34:13 Z Slavita Paint (COI20_paint) C++14
0 / 100
3000 ms 25324 KB
#include <bits/stdc++.h>
#define ve vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pi pair<int,int>
#define all(v) v.begin(),v.end()
#define si(v) (int)v.size()
#define en '\n'
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

const int N = 2e5 + 228;
const int big = 1e9;
int n, m, b[N], curCol, col;
map<pi, bool> mrk;
map<pi, int> re;
queue<int> X, Y;

void put(int x, int y){
    if (x < 1 || x > n || y < 1 || y > m) return;
    if (mrk[mp(x, y)]) return;
    if (re[mp(x, y)] != curCol) return;
    re[mp(x, y)] = col;
    mrk[mp(x, y)] = 1;
    X.push(x); Y.push(y);
}

void go(int x, int y){
    int st[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
    for (int i = 0; i < 4; i++) {
        put(x + st[i][0], y + st[i][1]);
    }
}

int main(){
    iostream::sync_with_stdio(false); cin.tie(0); ios_base::sync_with_stdio(false); cout.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    cin >> n >> m;
    int kol = 0;
    for (int i = 1; i <= n; i++){
        for (int j = 1; j <= m; j++){
            int x; cin >> x;
            re[mp(i, j)] = x;
        }
    }

    int q;
    cin >> q;
    while(q--){
        int x, y;
        cin >> x >> y >> col;
        curCol = re[mp(x, y)];
        put(x, y);
        while(!X.empty()){
            int x = X.front(); X.pop();
            int y = Y.front(); Y.pop();
            go(x, y);
        }
        for (int i = 1; i <= n; i++){
            for (int j = 1; j <= m; j++){
                mrk[mp(i, j)] = 0;
            }
        }
    }

    for (int i = 1; i <= n; i++){
        for (int j = 1; j <= m; j++){
            cout << re[mp(i, j)] << ' ';
        }
        cout << en;
    }

    return 0;
}
/*
12 11
1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 0 0 0 1 1 1 1
1 1 1 0 0 0 0 0 1 1 1
1 1 0 0 0 0 0 0 0 1 1
1 0 0 0 2 2 2 0 0 0 1
1 0 0 0 2 2 2 0 0 0 1
1 0 0 0 2 2 2 0 0 0 1
1 0 0 0 0 0 0 0 0 0 1
1 1 0 0 0 9 0 0 0 1 1
0 1 1 0 0 9 0 0 1 1 0
0 0 1 1 0 0 0 1 1 0 0
0 0 0 1 1 1 1 1 0 0 0
4
12 11 1
5 11 2
4 4 2
6 6 4
*/

Compilation message

paint.cpp: In function 'int main()':
paint.cpp:43:9: warning: unused variable 'kol' [-Wunused-variable]
   43 |     int kol = 0;
      |         ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 492 KB Output is correct
2 Correct 10 ms 620 KB Output is correct
3 Execution timed out 3090 ms 1644 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3084 ms 6636 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3062 ms 25324 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3069 ms 18668 KB Time limit exceeded
2 Halted 0 ms 0 KB -