217612026-01-13 19:31:24TaxiradioCseppkőbarlang (45 pont)cpp17Accepted 45/4525ms1332 KiB
// Source: https://usaco.guide/general/io

#include <algorithm>
#include <bits/stdc++.h>
using namespace std;

#define int int64_t

vector<array<int , 2>> d = {{-1 , 0} , {1 , 0} , {0 , -1} , {0 , 1}};
    vector<vector<int>> a;

int dfs(int x , int y){
    int o = a[x][y];
    a[x][y] = 0;
    int ans = o;
    for(auto [u , v] : d){
        if(a[x+u][y+v]!= 0)ans = min(ans , a[x+u][y+v]);
        if(a[x+u][y+v]!= 0 && a[x+u][y+v] == o)ans = min(dfs(x+u , y+v) , ans);
        if(a[x+u][y+v]!= 0 && a[x+u][y+v] > o)dfs(x+u , y+v);
    }
    return ans;
}

int32_t main() {
    int n , m ; cin >> n >> m;
    a.resize(n+2 , vector<int> (m+2 , 0));
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            int x; cin >> x;
            a[i+1][j+1] = x;
        }
    }
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            if(a[i][j] == 0)continue;
            int w = a[i][j];
            if(dfs(i , j) >= w)a[i][j] = w;
        }
    }
    vector<array<int , 2>> ans;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            if(a[i][j] != 0)ans.push_back({i , j});
        }
    }
    cout << ans.size() << endl;
    for(auto z:ans)cout << z[0] << " " << z[1] << "\n";
}
SubtaskSumTestVerdictTimeMemory
base45/45
1Accepted0/01ms316 KiB
2Accepted0/01ms500 KiB
3Accepted1/11ms316 KiB
4Accepted1/11ms316 KiB
5Accepted2/212ms1332 KiB
6Accepted2/212ms812 KiB
7Accepted2/210ms800 KiB
8Accepted2/21ms316 KiB
9Accepted2/21ms332 KiB
10Accepted3/319ms1296 KiB
11Accepted3/325ms1076 KiB
12Accepted3/319ms1080 KiB
13Accepted3/319ms1076 KiB
14Accepted3/314ms1092 KiB
15Accepted3/314ms1076 KiB
16Accepted3/314ms1076 KiB
17Accepted3/314ms1076 KiB
18Accepted3/316ms1080 KiB
19Accepted3/314ms1260 KiB
20Accepted3/324ms1076 KiB