Submission #131038

#TimeUsernameProblemLanguageResultExecution timeMemory
131038imyujinBodyguards (CEOI10_bodyguards)C++14
100 / 100
169 ms19348 KiB
#include <stdio.h> #include <vector> #include <algorithm> #include <functional> using namespace std; #define MAXR 200005 #define fi first #define se second typedef long long lint; typedef pair<int, int> pii; typedef pair<lint, lint> pll; vector<pll> rv, cv; int main() { int R, C; scanf("%d", &R); rv.resize(R); for(int i = 0; i < R; i++) scanf("%lld%lld", &rv[i].fi, &rv[i].se); scanf("%d", &C); cv.resize(C); for(int i = 0; i < C; i++) scanf("%lld%lld", &cv[i].fi, &cv[i].se); lint sumr = 0, sumc = 0; for(int i = 0; i < R; i++) sumr += rv[i].fi * rv[i].se; for(int i = 0; i < C; i++) sumc += cv[i].fi * cv[i].se; if(sumr != sumc) { printf("0"); return 0; } rv.push_back(make_pair(1ll << 30, 0)); sort(rv.begin(), rv.end(), greater<pll>()); sort(cv.begin(), cv.end(), greater<pll>()); vector<pll> v; for(int i = 0; i < cv.size(); i++) { if(i > 0 && cv[i - 1].fi == cv[i].fi) v.back().se += cv[i].se; else v.push_back(cv[i]); } swap(cv, v); for(int i = 1; i < cv.size(); i++) cv[i].se += cv[i - 1].se; rv[0].fi = rv[0].fi * rv[0].se; for(int i = 1; i < rv.size(); i++) { rv[i].fi = rv[i - 1].fi + rv[i].fi * rv[i].se; rv[i].se += rv[i - 1].se; } /* for(int i = 0; i < cv.size(); i++) printf("(%lld, %lld)", cv[i].fi, cv[i].se); printf("\n"); for(int i = 0; i < rv.size(); i++) printf("(%lld, %lld)", rv[i].fi, rv[i].se); printf("\n"); */ lint A = 0ll, h = 0ll; int p = cv.size() - 1; for(int i = 1; i < rv.size(); i++) { //printf("h = %lld, A = %lld, p = %d\n", h, A, p); if(A + cv[p].se < rv[i - 1].fi + (rv[i].fi - rv[i - 1].fi) / rv[i].se) { printf("0"); return 0; } while(p >= 0 && cv[p].fi <= rv[i].se) { A += (cv[p].fi - h) * cv[p].se; h = cv[p].fi; p--; } if(p < 0) break; A += (rv[i].se - h) * cv[p].se; h = rv[i].se; if(A < rv[i].fi) { printf("0"); return 0; } } printf("1"); return 0; }

Compilation message (stderr)

bodyguards.cpp: In function 'int main()':
bodyguards.cpp:41:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < cv.size(); i++) {
                 ~~^~~~~~~~~~~
bodyguards.cpp:46:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 1; i < cv.size(); i++) cv[i].se += cv[i - 1].se;
                 ~~^~~~~~~~~~~
bodyguards.cpp:48:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 1; i < rv.size(); i++) {
                 ~~^~~~~~~~~~~
bodyguards.cpp:62:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 1; i < rv.size(); i++) {
                 ~~^~~~~~~~~~~
bodyguards.cpp:21:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &R);
  ~~~~~^~~~~~~~~~
bodyguards.cpp:23:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i = 0; i < R; i++) scanf("%lld%lld", &rv[i].fi, &rv[i].se);
                             ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bodyguards.cpp:24:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &C);
  ~~~~~^~~~~~~~~~
bodyguards.cpp:26:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i = 0; i < C; i++) scanf("%lld%lld", &cv[i].fi, &cv[i].se);
                             ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...
#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...