結果

問題 No.1668 Grayscale
ユーザー rianoriano
提出日時 2021-06-14 21:44:14
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 659 ms / 4,000 ms
コード長 1,334 bytes
コンパイル時間 1,770 ms
コンパイル使用メモリ 175,028 KB
実行使用メモリ 44,112 KB
最終ジャッジ日時 2024-05-09 00:35:34
合計ジャッジ時間 5,756 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 659 ms
43,976 KB
testcase_07 AC 575 ms
43,984 KB
testcase_08 AC 150 ms
11,264 KB
testcase_09 AC 567 ms
44,112 KB
testcase_10 AC 532 ms
43,820 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 3 ms
5,376 KB
testcase_13 AC 33 ms
5,908 KB
testcase_14 AC 108 ms
13,228 KB
testcase_15 AC 80 ms
12,720 KB
testcase_16 AC 62 ms
8,372 KB
testcase_17 AC 24 ms
5,908 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 3 ms
5,376 KB
testcase_21 AC 3 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define Pr pair<ll,ll>
#define Tp tuple<ll,ll,ll>
using Graph = vector<vector<Pr>>;

ll mod = 998244353;

int main() {
    //FILE *in = freopen("grayscale/in/in22.txt", "r", stdin);
    //FILE *out = freopen("grayscale/out/in22.txt", "w", stdout);
    ll H,W,N; cin >> H >> W >> N;
    //assert(1<=H&&H<=1000&&1<=W&&W<=1000&&1<=N&&N<=H*W);
    ll col[H][W];
    //set<ll> num;
    rep(i,H){
        rep(j,W){
            cin >> col[i][j];
            //assert(1<=col[i][j]&&col[i][j]<=N);
            //num.insert(col[i][j]);
        }
    }
    //assert(num.size()==N);
    vector<Pr> range;
    rep(i,H){
        rep(j,W-1){
            ll a = col[i][j], b = col[i][j+1];
            if(a==b) continue;
            if(a>b) swap(a,b);
            range.push_back(make_pair(b,a));
        }
    }
    rep(i,H-1){
        rep(j,W){
            ll a = col[i][j], b = col[i+1][j];
            if(a==b) continue;
            if(a>b) swap(a,b);
            range.push_back(make_pair(b,a));
        }
    }
    sort(range.begin(),range.end());
    ll end = 0;
    ll ans = 1;
    for(auto p:range){
        ll a = p.second, b = p.first;
        if(a>=end){
            ans++; end = b;
        }
    }
    cout << ans << endl;
}
0