Submission #598420

#TimeUsernameProblemLanguageResultExecution timeMemory
598420imtore수족관 3 (KOI13_aqua3)C++14
100 / 100
552 ms42528 KiB
#include <stdio.h> #include <map> #include <set> #include <vector> #include <queue> #include <algorithm> #define LL long long #define pii pair<int, int> #define ff first #define ss second using namespace std; vector<int> X, Y; struct Line{ int sx, ex, y; Line(int sx, int ex, int y) : sx(sx), ex(ex), y(y) {} bool operator < (const Line &l) const { if(y != l.y) return y > l.y; return sx > l.sx; } }; struct Plane{ int sx, ex, sy, ey; }P[150021]; map<pii, int> mp; set<int> st1, st2; vector<int> edge[150021]; int par[150021]; priority_queue<LL> pq; LL dfs(int v){ LL mx = 0; for(int u : edge[v]){ LL res = dfs(u); if(mx < res){ if(mx) pq.push(mx); mx = res; } else pq.push(res); } return mx+(LL)(P[v].sx-P[v].ex)*(P[v].sy-P[v].ey); } int main(){ int n, k; scanf("%d", &n); for(int i = 1; i <= n; i++){ int x, y; scanf("%d %d", &x, &y); X.push_back(x); Y.push_back(y); } scanf("%d", &k); X.erase(unique(X.begin(), X.end()), X.end()); Y.erase(unique(Y.begin(), Y.end()), Y.end()); //for(int x : X) printf("%d ", x); printf("\n"); //for(int y : Y) printf("%d ", y); printf("\n"); vector<Line> L; for(int i = 1; i < X.size(); i++) L.push_back(Line(X[i-1], X[i], Y[i])); //for(Line l : L) printf("%d %d %d\n", l.sx, l.ex, l.y); printf("\n"); sort(L.begin(), L.end()); //for(Line l : L) printf("%d %d %d\n", l.sx, l.ex, l.y); printf("\n"); int piv = 0; mp[{X.front(), X.back()}] = ++piv; P[piv].sx = X.front(); P[piv].ex = X.back(); P[piv].sy = 0; st1.insert(X.front()); st1.insert(X.back()); while(!L.empty()){ int y = L.back().y; vector<int> vc; set<int> st; while(!L.empty() && L.back().y == y){ Line l = L.back(); L.pop_back(); set<int>::iterator it2 = st1.lower_bound(l.ex); set<int>::iterator it1 = it2; it1--; P[mp[{*it1, *it2}]].ey = y; if(st.find(*it1) == st.end()) st.insert(*it1); if(st.find(*it2) == st.end()) st.insert(*it2); if(st2.find(l.sx) == st2.end()) st2.insert(l.sx); else st2.erase(l.sx); if(st2.find(l.ex) == st2.end()) st2.insert(l.ex); else st2.erase(l.ex); vc.push_back(l.sx); vc.push_back(l.ex); } for(int x : st){ if(st2.find(x) == st2.end()) st2.insert(x); else st2.erase(x); } st.clear(); for(set<int>::iterator it21 = st2.begin(); it21 != st2.end(); it21++, it21++){ set<int>::iterator it22 = it21; it22++; set<int>::iterator it12 = st1.lower_bound(*it22); set<int>::iterator it11 = it12; it11--; mp[{*it21, *it22}] = ++piv; P[piv].sx = *it21; P[piv].ex = *it22; P[piv].sy = y; int p = mp[{*it11, *it12}]; edge[p].push_back(piv); par[piv] = p; } for(int x : vc){ if(st1.find(x) == st1.end()) st1.insert(x); else st1.erase(x); } st2.clear(); vc.clear(); } /* for(int i = 1; i <= piv; i++){ printf("%d : ", i); for(int u : edge[i]) printf("%d ", u); printf(": "); printf("%d %d %d %d\n", P[i].sx, P[i].ex, P[i].sy, P[i].ey); } printf("\n"); */ pq.push(dfs(1)); LL sum = 0; for(;!pq.empty() && k--; pq.pop()) sum += pq.top(); printf("%lld", sum); return 0; }

Compilation message (stderr)

aqua3.cpp: In function 'int main()':
aqua3.cpp:70:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |  for(int i = 1; i < X.size(); i++) L.push_back(Line(X[i-1], X[i], Y[i]));
      |                 ~~^~~~~~~~~~
aqua3.cpp:55:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   55 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
aqua3.cpp:57:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   57 |   int x, y; scanf("%d %d", &x, &y);
      |             ~~~~~^~~~~~~~~~~~~~~~~
aqua3.cpp:61:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   61 |  scanf("%d", &k);
      |  ~~~~~^~~~~~~~~~
#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...