結果

問題 No.2573 moving up
ユーザー MagentorMagentor
提出日時 2023-11-30 16:37:12
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 843 bytes
コンパイル時間 5,696 ms
コンパイル使用メモリ 326,208 KB
実行使用メモリ 6,548 KB
最終ジャッジ日時 2023-12-06 15:48:23
合計ジャッジ時間 6,321 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,548 KB
testcase_01 AC 4 ms
6,548 KB
testcase_02 AC 5 ms
6,548 KB
testcase_03 AC 3 ms
6,548 KB
testcase_04 AC 4 ms
6,548 KB
testcase_05 AC 4 ms
6,548 KB
testcase_06 AC 4 ms
6,548 KB
testcase_07 AC 3 ms
6,548 KB
testcase_08 AC 3 ms
6,548 KB
testcase_09 AC 3 ms
6,548 KB
testcase_10 AC 3 ms
6,548 KB
testcase_11 AC 2 ms
6,548 KB
testcase_12 AC 4 ms
6,548 KB
testcase_13 AC 4 ms
6,548 KB
testcase_14 AC 2 ms
6,548 KB
testcase_15 AC 2 ms
6,548 KB
testcase_16 AC 2 ms
6,548 KB
testcase_17 AC 2 ms
6,548 KB
testcase_18 AC 2 ms
6,548 KB
testcase_19 AC 4 ms
6,548 KB
testcase_20 AC 2 ms
6,548 KB
testcase_21 AC 2 ms
6,548 KB
testcase_22 AC 3 ms
6,548 KB
testcase_23 AC 3 ms
6,548 KB
testcase_24 AC 2 ms
6,548 KB
testcase_25 AC 3 ms
6,548 KB
testcase_26 AC 2 ms
6,548 KB
testcase_27 AC 2 ms
6,548 KB
testcase_28 AC 2 ms
6,548 KB
testcase_29 AC 2 ms
6,548 KB
testcase_30 AC 2 ms
6,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
typedef long long ll;
long long inf = 1000000000LL;
int main() {
int h,w;cin>>h>>w;
vector<ll> x(w);
vector<ll> y(w);
rep(i,w){cin>>x[i]>>y[i];}
ll t = 2;
while(t<=w){t*=2;}
mcf_graph<ll,ll> g(t*2+w+1);
rep(i,w){
  ll l = max(0LL,y[i]-x[i])+t;ll r = min(t,y[i])+t;
  while(l<r){
    if(l%2==1){
      g.add_edge(t*2+i,l,1LL,0LL);
      l++;}
    l /= 2;
    if(r%2==1){
      g.add_edge(t*2+i,r-1,1LL,0LL);
      r--;
    }
    r /= 2;
  }
}
rep(i,t-1){g.add_edge(t+i,t+i+1,inf,1LL);g.add_edge(t+1+i,t+i,inf,1LL);}
rep(i,w){g.add_edge(0,t*2+i,1LL,x[i]-1);
g.add_edge(t+i,t*2+w,1LL,0LL);
}
for(int i = 2;i<t*2;i++){
  g.add_edge(i/2,i,inf,0LL);
}
cout<<g.flow(0,t*2+w).second<<endl; 
}
0