結果
問題 | No.2573 moving up |
ユーザー |
![]() |
提出日時 | 2023-11-30 16:37:12 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 6 ms / 2,000 ms |
コード長 | 843 bytes |
コンパイル時間 | 6,763 ms |
コンパイル使用メモリ | 332,436 KB |
実行使用メモリ | 7,848 KB |
最終ジャッジ日時 | 2025-06-20 11:16:15 |
合計ジャッジ時間 | 6,987 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 32 |
ソースコード
#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; }