답안 #381546

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
381546 2021-03-25T09:41:05 Z Slavita Paint (COI20_paint) C++14
8 / 100
3000 ms 3436 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 = 1e4 + 228;
const int big = 1e9;
int n, m, b[N], curCol, col, re[N][N];
bool mrk[N][N];
queue<int> X, Y;

void put(int x, int y){
    if (x < 1 || x > n || y < 1 || y > m) return;
    if (mrk[x][y]) return;
    if (re[x][y] != curCol) return;
    re[x][y] = col;
    mrk[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;
    for (int i = 1; i <= n; i++){
        for (int j = 1; j <= m; j++){
            int x; cin >> x;
            re[i][j] = x;
        }
    }

    int q;
    cin >> q;
    while(q--){
        int x, y;
        cin >> x >> y >> col;
        curCol = re[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[i][j] = 0;
            }
        }
    }

    for (int i = 1; i <= n; i++){
        for (int j = 1; j <= m; j++){
            cout << re[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
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 2 ms 748 KB Output is correct
3 Correct 40 ms 620 KB Output is correct
4 Correct 45 ms 1108 KB Output is correct
5 Correct 649 ms 1260 KB Output is correct
6 Correct 1044 ms 1260 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2415 ms 672 KB Output is correct
2 Execution timed out 3057 ms 876 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3091 ms 2156 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3055 ms 3436 KB Time limit exceeded
2 Halted 0 ms 0 KB -