Submission #1174906

#TimeUsernameProblemLanguageResultExecution timeMemory
1174906dzhoz0지구 온난화 (NOI13_gw)C++20
40 / 40
176 ms31612 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define INF 1e18 #define f first #define s second #define pii pair<int, int> #define vi vector<int> const int MOD = 1'000'000'000 + 7; void setIO(string name = "") { ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); #ifdef LOCAL freopen("inp.txt", "r", stdin); freopen("out.txt", "w", stdout); #else if (!name.empty()) { freopen((name + ".INP").c_str(), "r", stdin); freopen((name + ".OUT").c_str(), "w", stdout); } #endif } // START OF DEBUG #define db(val) "["#val" = "<<(val)<<"] " #define print_op(...) ostream& operator<<(ostream& out, const __VA_ARGS__& u) // for printing std::pair template<class U, class V> print_op(pair<U, V>) { return out << "(" << u.first << ", " << u.second << ")"; } // for printing collection template<class Con, class = decltype(begin(declval<Con>()))> typename enable_if<!is_same<Con, string>::value, ostream&>::type operator<<(ostream& out, const Con& con) { out << "{"; for (auto beg = con.begin(), it = beg; it != con.end(); ++it) out << (it == beg ? "" : ", ") << *it; return out << "}"; } // for printing std::tuple template<size_t i, class T> ostream& print_tuple_utils(ostream& out, const T& tup) { if constexpr(i == tuple_size<T>::value) return out << ")"; else return print_tuple_utils<i + 1, T>(out << (i ? ", " : "(") << get<i>(tup), tup); } template<class ...U> print_op(tuple<U...>) { return print_tuple_utils<0, tuple<U...>>(out, u); } // END OF DEBUG const int MAXN = 1e6; int par[MAXN + 5]; int sz[MAXN + 5]; int numCmps = 0; void make_set(int v) { par[v] = v; sz[v] = 1; numCmps++; } int find_set(int v) { if(par[v] == v) return v; return par[v] = find_set(par[v]); } void union_set(int u, int v) { u = find_set(u); v = find_set(v); if(u != v) { if(sz[u] < sz[v]) swap(u, v); par[v] = u; sz[u] += sz[v]; numCmps--; } } void solve() { int n; cin >> n; vector<pii> v(n); for(int i = 0; i < n; i++) { cin >> v[i].f; v[i].s = i; par[i] = -1; } sort(v.rbegin(), v.rend()); // cout << v << '\n'; int res = 0; for(int x = 0; x < n; x++) { int i = v[x].s; // cout << db(i) << '\n'; make_set(i); for(int j : {i - 1, i + 1}) { if(j >= 0 && j < n) { if(par[j] != -1) { // cout << i << ' ' << j << '\n'; // cout << par[j] << '\n'; union_set(i, j); } } } if(x == n - 1 || v[x].f != v[x + 1].f) { // cout << db(i) << ' ' << db(numCmps) << '\n'; res = max(res, numCmps); } } cout << res << '\n'; } signed main() { setIO(); int t = 1; // cin >> t; while (t--) solve(); }

Compilation message (stderr)

gw.cpp: In function 'void setIO(std::string)':
gw.cpp:23:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |         freopen((name + ".INP").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
gw.cpp:24:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |         freopen((name + ".OUT").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...