結果
問題 | No.1194 Replace |
ユーザー | HIR180 |
提出日時 | 2020-08-22 14:22:28 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 894 ms / 2,000 ms |
コード長 | 1,894 bytes |
コンパイル時間 | 3,521 ms |
コンパイル使用メモリ | 253,728 KB |
実行使用メモリ | 61,232 KB |
最終ジャッジ日時 | 2024-04-23 08:44:06 |
合計ジャッジ時間 | 17,070 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 557 ms
39,524 KB |
testcase_01 | AC | 604 ms
41,788 KB |
testcase_02 | AC | 462 ms
34,756 KB |
testcase_03 | AC | 368 ms
29,912 KB |
testcase_04 | AC | 596 ms
41,680 KB |
testcase_05 | AC | 548 ms
38,988 KB |
testcase_06 | AC | 505 ms
36,772 KB |
testcase_07 | AC | 894 ms
61,000 KB |
testcase_08 | AC | 867 ms
61,000 KB |
testcase_09 | AC | 878 ms
61,004 KB |
testcase_10 | AC | 864 ms
61,232 KB |
testcase_11 | AC | 875 ms
61,004 KB |
testcase_12 | AC | 885 ms
61,004 KB |
testcase_13 | AC | 434 ms
23,328 KB |
testcase_14 | AC | 348 ms
19,388 KB |
testcase_15 | AC | 298 ms
21,836 KB |
testcase_16 | AC | 421 ms
23,616 KB |
testcase_17 | AC | 277 ms
19,864 KB |
testcase_18 | AC | 276 ms
17,568 KB |
testcase_19 | AC | 426 ms
24,776 KB |
testcase_20 | AC | 1 ms
6,944 KB |
testcase_21 | AC | 2 ms
6,940 KB |
testcase_22 | AC | 1 ms
6,944 KB |
testcase_23 | AC | 114 ms
11,876 KB |
testcase_24 | AC | 36 ms
7,424 KB |
testcase_25 | AC | 14 ms
6,940 KB |
testcase_26 | AC | 131 ms
9,848 KB |
testcase_27 | AC | 20 ms
6,940 KB |
testcase_28 | AC | 57 ms
6,940 KB |
testcase_29 | AC | 7 ms
6,944 KB |
ソースコード
//Let's join Kaede Takagaki Fan Club !! #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; typedef long long ll; typedef pair<int,int> P; typedef pair<int,P> P1; typedef pair<P,P> P2; #define pu push #define pb push_back #define mp make_pair #define eps 1e-7 #define INF 1000000000 #define fi first #define sc second #define rep(i,x) for(int i=0;i<x;i++) #define repn(i,x) for(int i=1;i<=x;i++) #define SORT(x) sort(x.begin(),x.end()) #define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end()) #define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) #define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) #define all(x) x.begin(),x.end() template<class T> void dmp(T a){ rep(i,a.size()) cout << a[i] << " "; cout << endl; } template<class T> bool chmax(T&a, T b){ if(a < b){ a = b; return 1; } return 0; } template<class T> bool chmin(T&a, T b){ if(a > b){ a = b; return 1; } return 0; } template<class T> void g(T &a){ cin >> a; } template<class T> void o(const T &a,bool space=false){ cout << a << (space?' ':'\n'); } //ios::sync_with_stdio(false); const ll mod = 998244353; template<class T> void add(T&a,T b){ a+=b; if(a >= mod) a-=mod; } map<int, int>M; int n, m; map<int, vector<int>>E; vector<int>vec; int main(){ cin >> n >> m; rep(i, m){ int a, b; cin >> a >> b; vec.pb(a); vec.pb(b); E[b].pb(a); } SORT(vec); ERASE(vec); reverse(all(vec)); rep(i, vec.size()){ int q = vec[i]; queue<int>que; que.push(q); while(!que.empty()){ int q = que.front(); que.pop(); if(M.find(q) != M.end()) continue; M[q] = vec[i]; for(auto at:E[q]){ if(M.find(at) == M.end()) que.push(at); } } } ll ans = 1LL*n*(n+1)/2; rep(i, vec.size()) ans += M[vec[i]] - vec[i]; cout << ans << endl; }