Submission #296802

#TimeUsernameProblemLanguageResultExecution timeMemory
296802BruteforcemanJust Long Neckties (JOI20_ho_t1)C++11
100 / 100
333 ms19448 KiB
#include "bits/stdc++.h" using namespace std; int n; int a[200010], b[200010], aux[200010]; int pre[200010], suf[200010]; int solve(int p) { vector <int> u, v; for(int i = 1; i <= (n + 1); i++) { if(i != p) u.push_back(a[i]); } for(int i = 1; i <= n; i++) { v.push_back(b[i]); } sort(u.begin(), u.end()); sort(v.begin(), v.end()); int ans = 0; for(int i = 0; i < u.size(); i++) { ans = max(ans, u[i] - v[i]); } return ans; } int main(int argc, char const *argv[]) { srand(time(NULL)); scanf("%d", &n); map <int, int> id; for(int i = 1; i <= n+1; i++) { scanf("%d", &a[i]); aux[i] = a[i]; } for(int i = 1; i <= n; i++) { scanf("%d", &b[i]); } sort(a + 1, a + n + 2); sort(b + 1, b + n + 1); for(int i = 1; i <= n + 1; i++) { id[a[i]] = i; } for(int i = n+1; i >= 2; i--) { suf[i] = max(suf[i + 1], a[i] - b[i - 1]); } for(int i = 1; i <= n; i++) { pre[i] = max(pre[i - 1], a[i] - b[i]); } for(int i = 1; i <= n + 1; i++) { int x = id[aux[i]]; printf("%d ", max(pre[x - 1], suf[x + 1])); } printf("\n"); return 0; }

Compilation message (stderr)

ho_t1.cpp: In function 'int solve(int)':
ho_t1.cpp:18:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |  for(int i = 0; i < u.size(); i++) {
      |                 ~~^~~~~~~~~~
ho_t1.cpp: In function 'int main(int, const char**)':
ho_t1.cpp:27:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   27 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
ho_t1.cpp:30:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   30 |   scanf("%d", &a[i]);
      |   ~~~~~^~~~~~~~~~~~~
ho_t1.cpp:34:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   34 |   scanf("%d", &b[i]);
      |   ~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...