結果
問題 | No.1194 Replace |
ユーザー | auaua |
提出日時 | 2020-08-22 17:25:21 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 1,328 ms / 2,000 ms |
コード長 | 1,674 bytes |
コンパイル時間 | 1,968 ms |
コンパイル使用メモリ | 184,672 KB |
実行使用メモリ | 76,928 KB |
最終ジャッジ日時 | 2024-04-23 11:21:57 |
合計ジャッジ時間 | 22,005 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 860 ms
52,692 KB |
testcase_01 | AC | 941 ms
55,908 KB |
testcase_02 | AC | 702 ms
45,584 KB |
testcase_03 | AC | 543 ms
39,096 KB |
testcase_04 | AC | 910 ms
55,708 KB |
testcase_05 | AC | 826 ms
52,140 KB |
testcase_06 | AC | 758 ms
48,672 KB |
testcase_07 | AC | 1,287 ms
76,664 KB |
testcase_08 | AC | 1,328 ms
76,660 KB |
testcase_09 | AC | 1,325 ms
76,824 KB |
testcase_10 | AC | 1,303 ms
76,760 KB |
testcase_11 | AC | 1,315 ms
76,928 KB |
testcase_12 | AC | 1,295 ms
76,900 KB |
testcase_13 | AC | 665 ms
39,148 KB |
testcase_14 | AC | 546 ms
33,732 KB |
testcase_15 | AC | 489 ms
31,968 KB |
testcase_16 | AC | 643 ms
38,420 KB |
testcase_17 | AC | 431 ms
29,592 KB |
testcase_18 | AC | 403 ms
28,124 KB |
testcase_19 | AC | 648 ms
38,920 KB |
testcase_20 | AC | 2 ms
6,944 KB |
testcase_21 | AC | 2 ms
6,940 KB |
testcase_22 | AC | 1 ms
6,940 KB |
testcase_23 | AC | 159 ms
16,112 KB |
testcase_24 | AC | 48 ms
8,320 KB |
testcase_25 | AC | 20 ms
6,944 KB |
testcase_26 | AC | 199 ms
16,900 KB |
testcase_27 | AC | 32 ms
6,944 KB |
testcase_28 | AC | 90 ms
9,856 KB |
testcase_29 | AC | 9 ms
6,944 KB |
ソースコード
#include<bits/stdc++.h> using namespace std; #define int long long #define REP(i,m,n) for(int i=(m);i<(n);i++) #define rep(i,n) REP(i,0,n) #define pb push_back #define all(a) a.begin(),a.end() #define rall(c) (c).rbegin(),(c).rend() #define mp make_pair #define endl '\n' #define vec vector<ll> #define mat vector<vector<ll> > #define fi first #define se second typedef long long ll; typedef unsigned long long ull; typedef pair<ll,ll> pll; typedef long double ld; typedef complex<double> comp; const ll inf=1e9+7; const ll mod=998244353; const int MAX=300010; signed main(){ ll n,m;cin>>n>>m; map<ll,ll>idx; vector<ll>inv(2*m); map<ll,ll>con; vector<vector<ll> >G(2*m); ll now=0; vector<ll>q(m); rep(i,m){ ll b,c;cin>>b>>c; con[b]=b; con[c]=c; q[i]=c; if(idx.find(c)==idx.end()){ idx[c]=now; now++; } if(idx.find(b)==idx.end()){ idx[b]=now; now++; } inv[idx[c]]=c; inv[idx[b]]=b; G[idx[c]].pb(idx[b]); } sort(rall(q)); vector<ll>used(2*m); rep(i,m){ if(used[idx[q[i]]])continue; ll c=q[i]; queue<ll>q; used[idx[c]]=1; q.push(idx[c]); while(!q.empty()){ ll k=q.front(); q.pop(); //cout<<inv[k]<<' '<<c<<endl; for(auto e:G[k]){ if(used[e])continue; con[inv[e]]=max(con[inv[e]],c); used[e]=1; q.push(e); } } } ll ans=n*(n+1)/2; for(auto e:con){ ans+=e.se-e.fi; } cout<<ans<<endl; }