217612026-01-13 19:31:24TaxiradioCseppkőbarlang (45 pont)cpp17Elfogadva 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";
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base45/45
1Elfogadva0/01ms316 KiB
2Elfogadva0/01ms500 KiB
3Elfogadva1/11ms316 KiB
4Elfogadva1/11ms316 KiB
5Elfogadva2/212ms1332 KiB
6Elfogadva2/212ms812 KiB
7Elfogadva2/210ms800 KiB
8Elfogadva2/21ms316 KiB
9Elfogadva2/21ms332 KiB
10Elfogadva3/319ms1296 KiB
11Elfogadva3/325ms1076 KiB
12Elfogadva3/319ms1080 KiB
13Elfogadva3/319ms1076 KiB
14Elfogadva3/314ms1092 KiB
15Elfogadva3/314ms1076 KiB
16Elfogadva3/314ms1076 KiB
17Elfogadva3/314ms1076 KiB
18Elfogadva3/316ms1080 KiB
19Elfogadva3/314ms1260 KiB
20Elfogadva3/324ms1076 KiB