結果

問題 No.2731 Two Colors
ユーザー 矢澤式WINTER矢澤式WINTER
提出日時 2024-04-19 23:18:03
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,617 bytes
コンパイル時間 3,920 ms
コンパイル使用メモリ 293,104 KB
実行使用メモリ 66,176 KB
最終ジャッジ日時 2024-04-19 23:18:17
合計ジャッジ時間 12,909 ms
ジャッジサーバーID
(参考情報)
judge6 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,109 ms
66,176 KB
testcase_01 AC 1,105 ms
66,048 KB
testcase_02 AC 1,109 ms
66,048 KB
testcase_03 AC 4 ms
6,944 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 43 ms
8,064 KB
testcase_08 AC 9 ms
6,940 KB
testcase_09 AC 161 ms
19,600 KB
testcase_10 WA -
testcase_11 AC 268 ms
26,268 KB
testcase_12 AC 155 ms
19,488 KB
testcase_13 AC 227 ms
22,532 KB
testcase_14 WA -
testcase_15 AC 10 ms
6,944 KB
testcase_16 AC 97 ms
12,496 KB
testcase_17 AC 122 ms
14,884 KB
testcase_18 WA -
testcase_19 AC 103 ms
13,040 KB
testcase_20 WA -
testcase_21 AC 25 ms
6,944 KB
testcase_22 WA -
testcase_23 AC 54 ms
8,704 KB
testcase_24 AC 28 ms
6,940 KB
testcase_25 AC 3 ms
6,940 KB
testcase_26 WA -
testcase_27 AC 184 ms
21,980 KB
testcase_28 WA -
testcase_29 AC 50 ms
8,064 KB
testcase_30 AC 69 ms
10,496 KB
testcase_31 AC 61 ms
9,084 KB
testcase_32 WA -
testcase_33 AC 2 ms
6,940 KB
testcase_34 AC 1 ms
6,940 KB
testcase_35 AC 1 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
/*/
#include <atcoder/all>
using namespace atcoder;
//*/
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define ALL(x) (x).begin(),(x).end()
#define dbgv(x); for(auto now : x) cout << now << " "; cout << endl;
//using P = pair<int,int>;
using ll = long long;
using ull = unsigned long long;
//*/
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<int> vint;
random_device rnd;
mt19937 rng(rnd());
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0}; 
void solve(){
  int h,w; cin >> h >> w;
  vector<vll> a(h,vll(w)); rep(i,h)rep(j,w) cin >> a[i][j];
  vector<vll> c(h,vll(w,0));
  priority_queue<pair<ll,pair<int,int>>,vector<pair<ll,pair<int,int>>>,greater<pair<ll,pair<int,int>>>> z,o;
  int var = 1;
  int ans = 0;
  set<pair<int,int>> zz,oo;
  c[0][0] = 1;
  c[h-1][w-1] = -1;
  rep(i,4){
    if(dx[i] >= 0 && dy[i] >= 0) o.push(make_pair(a[dx[i]][dy[i]],make_pair(dx[i],dy[i])));
  }
  rep(i,4){
    if(dx[i] <= 0 && dy[i] <= 0) z.push(make_pair(a[h-1+dx[i]][w-1+dy[i]],make_pair(h-1+dx[i],w-1+dy[i])));
  }
  while(1){
    bool bre = false;
    ans++;
    if(var == 1){
      auto pp = o.top(); o.pop();
      auto [_,p] = pp;
      rep(i,4){
        int ni = p.first+dx[i];
        int nj = p.second+dy[i];
        if(ni < 0 || nj < 0 || ni >= h || nj >= w || c[ni][nj] == var) continue;
        if(c[ni][nj] == -1) bre = true;
        else{
          if(oo.find(make_pair(ni,nj)) == oo.end()) o.push(make_pair(a[ni][nj],make_pair(ni,nj)));
          oo.insert(make_pair(ni,nj));
        }
      }
      c[p.first][p.second] = var;
    }else{
      auto pp = z.top(); z.pop();
      auto [_,p] = pp;
      rep(i,4){
        int ni = p.first+dx[i];
        int nj = p.second+dy[i];
        if(ni < 0 || nj < 0 || ni >= h || nj >= w || c[ni][nj] == var) continue;
        if(c[ni][nj] == 1) bre = true;
        else{
          if(zz.find(make_pair(ni,nj)) == zz.end()) z.push(make_pair(a[ni][nj],make_pair(ni,nj)));
          zz.insert(make_pair(ni,nj));
        }
      }
      c[p.first][p.second] = var;
    }
    var *= -1;
    if(bre){
      ans = 0;
      rep(i,h){
        rep(j,w){
          if(c[i][j] != 0) ans++;
        }
      }
      cout << ans-2 << endl;
      return;
    }
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int t = 1; //cin >> t;
  rep(dirc,t) solve();
}
0