Submission #492967

#TimeUsernameProblemLanguageResultExecution timeMemory
492967kevinRoller Coaster Railroad (IOI16_railroad)C++17
0 / 100
335 ms28032 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define all(x) x.begin(), x.end() #define f first #define s second #define ca(v) for(auto i:v) cout<<i<<" "; #define nl cout<<"\n" const int MAXN = 5e5 + 5; ll plan_roller_coaster(vector<int> s, vector<int> t){ int N = s.size(); unordered_map<int, int> hsh; vector<int> cmp; for(int i=0; i<N; i++) { cmp.push_back(s[i]); cmp.push_back(t[i]); } sort(all(cmp)); cmp.resize(unique(all(cmp)) - cmp.begin()); for(int i=0; i<cmp.size(); i++) hsh[cmp[i]] = i; vector<int> in(cmp.size(), 0); vector<int> out(cmp.size(), 0); for(int i=0; i<N; i++) out[hsh[s[i]]]++; // greedily assign right arrows vector<int> rgt; for(int i=0; i<N; i++) rgt.push_back(hsh[t[i]]); sort(all(rgt)); int p = 0; for(int i:rgt){ p = max(p, i); while(p<cmp.size() && out[p] == in[p]) p++; if(p<cmp.size()){ in[p]++; } else break; } int flg = 0; for(int i=0; i<cmp.size(); i++){ if(out[i] > in[i]) { if(flg || out[i] - in[i] > 1) return 1; flg = 1; } } return 0; }

Compilation message (stderr)

railroad.cpp: In function 'long long int plan_roller_coaster(std::vector<int>, std::vector<int>)':
railroad.cpp:23:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |     for(int i=0; i<cmp.size(); i++) hsh[cmp[i]] = i;
      |                  ~^~~~~~~~~~~
railroad.cpp:37:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |         while(p<cmp.size() && out[p] == in[p]) p++;
      |               ~^~~~~~~~~~~
railroad.cpp:38:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |         if(p<cmp.size()){
      |            ~^~~~~~~~~~~
railroad.cpp:44:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |     for(int i=0; i<cmp.size(); i++){
      |                  ~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...