結果

問題 No.1668 Grayscale
ユーザー harurunharurun
提出日時 2021-09-03 22:09:35
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,024 ms / 4,000 ms
コード長 1,172 bytes
コンパイル時間 1,168 ms
コンパイル使用メモリ 85,536 KB
実行使用メモリ 65,920 KB
最終ジャッジ日時 2024-05-09 04:17:13
合計ジャッジ時間 5,123 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 ms
5,376 KB
testcase_06 AC 429 ms
65,920 KB
testcase_07 AC 428 ms
65,920 KB
testcase_08 AC 199 ms
27,524 KB
testcase_09 AC 1,024 ms
64,640 KB
testcase_10 AC 500 ms
34,176 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 3 ms
5,376 KB
testcase_13 AC 35 ms
7,040 KB
testcase_14 AC 132 ms
14,464 KB
testcase_15 AC 82 ms
9,600 KB
testcase_16 AC 54 ms
7,808 KB
testcase_17 AC 25 ms
5,760 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 3 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
using ll=long long;

int main(){
  ll H,W,N;
  cin>>H>>W>>N;
  vector<vector<ll>>C(H,vector<ll>(W));
  vector<vector<pair<ll,ll>>>d(N);
  for(ll i=0;i<H;i++){
    for(ll j=0;j<W;j++){
      cin>>C.at(i).at(j);
      C.at(i).at(j)--;
      d.at(C.at(i).at(j)).emplace_back(make_pair(i,j));
    }
  }
  //cerr<<"input\n";
  ll ans=0,x,y,start=0;
  bool flag;
  const vector<pair<ll,ll>> around={{1,0},{0,1},{-1,0},{0,-1}};
  for(ll i=0;i<N;i++){
    flag=true;
    for(pair<ll,ll> j:d.at(i)){
      x=j.first;
      y=j.second;
      for(pair<ll,ll> k:around){
        if(0<=x+k.first && x+k.first<H && 0<=y+k.second && y+k.second<W){
          if(C.at(x+k.first).at(y+k.second)>=start 
          && C.at(x).at(y)>C.at(x+k.first).at(y+k.second)){
            ans++;
            flag=false;
            start=C.at(x).at(y);
            //cerr<<C.at(x).at(y)+1<<endl;
            break;
          }
        }
      }
      if(!flag){
        break;
      }
    }
  }
  //cerr<<flag<<endl;
  //if(flag){
    ans++;
  //}
  printf("%lld\n",ans);
  return 0;
}
0