Submission #996112

#TimeUsernameProblemLanguageResultExecution timeMemory
996112faqinyeagerStove (JOI18_stove)C++17
0 / 100
1 ms348 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; int n, k; vector<ll> t; int main(){ cin >> n >> k; t.resize(n); for(int i = 0; i < n; i++) cin >> t[i]; if(n <= k){ cout << n; return 0; } vector<pair<ll, pair<ll, ll>>> pos(n - 1); for(int i = 0; i < n - 1; i++){ int p = t[i + 1] - t[i]; pos[i].first = p; pos[i].second = {i, i + 1}; } sort(pos.begin(), pos.end()); for(int i = 0; i < n - 1; i++) cout << pos[i].second.first << ' ' << pos[i].second.second << " , cost - " << pos[i].first << '\n'; cout << '\n'; vector<pair<pair<ll, ll>, ll>> tmp; for(int i = 0; i < n - k; i++) tmp.push_back({{pos[i].second.first + 1, pos[i].second.second + 1}, pos[i].first}); int m = tmp.size(); sort(tmp.begin(), tmp.end()); for(int i = 0; i < m; i++) cout << tmp[i].first.first << ' ' << tmp[i].first.second << '\n'; cout << '\n'; map<ll, ll> parent; for(int i = 0; i < m; i++){ if(parent[tmp[i].first.first] == 0) parent[tmp[i].first.second] = tmp[i].first.first; else{ parent[tmp[i].first.second] = parent[tmp[i].first.first]; parent[tmp[i].first.first] = 0; } } ll ans = 0; ll last = 0; for(auto x: parent){ if(x.first != 0 && x.second != 0){ ans += t[x.first - 1] - t[x.second - 1] + 1; last++; } } ans += (k - last); cout << ans; //for(auto x: pos) cout << x.first << ' ' << x.second.first << ' ' << x.second.second << '\n'; }

Compilation message (stderr)

stove.cpp: In function 'int main()':
stove.cpp:28:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   28 |     for(int i = 0; i < n - 1; i++) cout << pos[i].second.first << ' ' << pos[i].second.second << " , cost - " << pos[i].first << '\n';  cout << '\n';
      |     ^~~
stove.cpp:28:137: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   28 |     for(int i = 0; i < n - 1; i++) cout << pos[i].second.first << ' ' << pos[i].second.second << " , cost - " << pos[i].first << '\n';  cout << '\n';
      |                                                                                                                                         ^~~~
stove.cpp:37:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   37 |     for(int i = 0; i < m; i++) cout << tmp[i].first.first << ' ' << tmp[i].first.second << '\n'; cout << '\n';
      |     ^~~
stove.cpp:37:98: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   37 |     for(int i = 0; i < m; i++) cout << tmp[i].first.first << ' ' << tmp[i].first.second << '\n'; cout << '\n';
      |                                                                                                  ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...