結果

問題 No.1668 Grayscale
ユーザー harurunharurun
提出日時 2021-09-03 22:09:35
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 909 ms / 4,000 ms
コード長 1,172 bytes
コンパイル時間 784 ms
コンパイル使用メモリ 85,272 KB
実行使用メモリ 65,952 KB
最終ジャッジ日時 2023-08-21 22:05:04
合計ジャッジ時間 4,794 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 404 ms
65,952 KB
testcase_07 AC 406 ms
65,400 KB
testcase_08 AC 181 ms
29,216 KB
testcase_09 AC 909 ms
64,344 KB
testcase_10 AC 407 ms
33,972 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 31 ms
7,004 KB
testcase_14 AC 118 ms
14,144 KB
testcase_15 AC 70 ms
9,228 KB
testcase_16 AC 47 ms
7,316 KB
testcase_17 AC 21 ms
5,536 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 3 ms
4,376 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 2 ms
4,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