結果
問題 | No.1194 Replace |
ユーザー | cn_449 |
提出日時 | 2020-08-22 15:04:51 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 942 ms / 2,000 ms |
コード長 | 1,867 bytes |
コンパイル時間 | 1,446 ms |
コンパイル使用メモリ | 150,848 KB |
実行使用メモリ | 59,904 KB |
最終ジャッジ日時 | 2024-04-23 09:27:41 |
合計ジャッジ時間 | 15,237 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 565 ms
38,528 KB |
testcase_01 | AC | 628 ms
40,448 KB |
testcase_02 | AC | 468 ms
33,792 KB |
testcase_03 | AC | 351 ms
29,440 KB |
testcase_04 | AC | 604 ms
40,576 KB |
testcase_05 | AC | 568 ms
38,144 KB |
testcase_06 | AC | 500 ms
35,968 KB |
testcase_07 | AC | 916 ms
59,648 KB |
testcase_08 | AC | 933 ms
59,648 KB |
testcase_09 | AC | 942 ms
59,904 KB |
testcase_10 | AC | 940 ms
59,776 KB |
testcase_11 | AC | 921 ms
59,776 KB |
testcase_12 | AC | 919 ms
59,648 KB |
testcase_13 | AC | 386 ms
22,272 KB |
testcase_14 | AC | 331 ms
18,304 KB |
testcase_15 | AC | 293 ms
20,992 KB |
testcase_16 | AC | 405 ms
22,400 KB |
testcase_17 | AC | 265 ms
19,200 KB |
testcase_18 | AC | 258 ms
16,768 KB |
testcase_19 | AC | 391 ms
23,424 KB |
testcase_20 | AC | 2 ms
6,940 KB |
testcase_21 | AC | 2 ms
6,944 KB |
testcase_22 | AC | 1 ms
6,944 KB |
testcase_23 | AC | 96 ms
11,648 KB |
testcase_24 | AC | 32 ms
7,168 KB |
testcase_25 | AC | 10 ms
6,940 KB |
testcase_26 | AC | 104 ms
9,600 KB |
testcase_27 | AC | 13 ms
6,940 KB |
testcase_28 | AC | 43 ms
6,940 KB |
testcase_29 | AC | 6 ms
6,940 KB |
ソースコード
#include <iostream> #include <vector> #include <algorithm> #include <cmath> #include <string> #include <queue> #include <stack> #include <set> #include <map> #include <iomanip> #include <utility> #include <tuple> #include <functional> #include <bitset> #include <cassert> #include <complex> #include <stdio.h> #include <time.h> #include <numeric> #include <random> #include <unordered_map> #include <unordered_set> #define all(a) a.begin(),a.end() #define rep(i, n) for (ll i = 0; i < (n); i++) #define pb push_back #define debug(x) cerr << __LINE__ << ' ' << #x << ':' << x << '\n' #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<ll, ll> P; typedef complex<ld> com; constexpr int inf = 1000000010; constexpr ll INF = 1000000000000000010; constexpr ld eps = 1e-12; constexpr ld pi = 3.141592653589793238; template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; } template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; } int main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); ll n, m; cin >> n >> m; map<int, vector<int>> graph; set<int> st; rep(i, m) { int b, c; cin >> b >> c; graph[c].pb(b); st.insert(c); } map<int, int> val; while (st.size() > 0) { int s = *st.rbegin(); queue<int> que; que.push(s); val[s] = s; st.erase(s); while (!que.empty()) { int p = que.front(); que.pop(); for (int i : graph[p]) { if (val.count(i) == 0) { val[i] = s; que.push(i); st.erase(i); } } } } ll ans = n * (n + 1) / 2; for (auto i : val) { ll x = i.first; ll y = i.second; if (x < y) ans += y - x; } cout << ans << '\n'; }