結果
問題 | No.808 Kaiten Sushi? |
ユーザー |
![]() |
提出日時 | 2019-03-22 21:43:40 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 544 ms / 2,000 ms |
コード長 | 1,519 bytes |
コンパイル時間 | 1,015 ms |
コンパイル使用メモリ | 104,224 KB |
実行使用メモリ | 31,616 KB |
最終ジャッジ日時 | 2024-09-19 04:01:40 |
合計ジャッジ時間 | 11,252 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 56 |
ソースコード
#include<iostream> #include<string> #include<algorithm> #include<vector> #include<iomanip> #include<math.h> #include<complex> #include<queue> #include<deque> #include<stack> #include<map> #include<set> #include<bitset> #include<functional> #include<assert.h> #include<numeric> using namespace std; #define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i ) #define rep(i,n) REP(i,0,n) typedef long long ll; typedef pair<int,int> pint; typedef pair<ll,int> pli; const int inf=1e9+7; const ll longinf=1LL<<60 ; const ll mod=1e9+7 ; int main(){ int n; cin>>n; ll T; cin>>T; set<ll> sushi,tea; rep(i,n){ ll x; cin>>x; sushi.insert(x); sushi.insert(T+x); sushi.insert(2*T+x); } rep(i,n){ ll x; cin>>x; tea.insert(x); tea.insert(T+x); tea.insert(2*T+x); } ll cur=0; int cnt=0; ll ans=0; while(1){ auto itr=sushi.lower_bound(cur); ans+=*itr-cur; ll ret=*itr; if(ret>T)ret-=T; sushi.erase(ret); sushi.erase(ret+T); sushi.erase(ret+2*T); ll res=*tea.lower_bound(ret); if(cnt==n-1){ ans+=res-ret; break; } ll nxt=*sushi.lower_bound(res); res=*prev(tea.lower_bound(nxt)); ans+=res-ret; while(res>T)res-=T; tea.erase(res); tea.erase(res+T); tea.erase(res+2*T); cur=res; ++cnt; } cout<<ans<<endl; return 0; }