Submission #843883

#TimeUsernameProblemLanguageResultExecution timeMemory
843883ogkostyaOvertaking (IOI23_overtaking)C++17
65 / 100
3509 ms18256 KiB
#include "overtaking.h" #include <algorithm> #include <utility> std::vector<std::vector<std::pair<long long, long long>>> SS(1001, std::vector<std::pair<long long, long long>>()); struct sort1 { inline bool operator() (const std::pair<long long, int>& a, const std::pair<long long, int>& b) { return (a.first < b.first); } }; struct sort2 { inline bool operator() (const std::pair<long long, long long>& a, const std::pair<long long, long long>& b) { return a.first < b.first; } }; void sortVecPair(std::vector<long long>& vecA, std::vector<int>& vecB) { std::vector<std::pair<long long, int>> vecC; vecC.reserve(vecA.size()); for (int i = 0; i < vecA.size(); i++) { vecC.push_back(std::make_pair(vecA[i], vecB[i])); } std::sort(vecC.begin(), vecC.end(), sort1()); vecA.clear(); vecB.clear(); vecA.reserve(vecC.size()); vecB.reserve(vecC.size()); for (int i = 0; i < vecC.size(); i++) { vecA.push_back(vecC[i].first); vecB.push_back(vecC[i].second); } } int _M; std::vector<int> _S; int _X; void init(int L, int N, std::vector<long long> T, std::vector<int> W, int X, int M, std::vector<int> S) { _X = X; _M = M; _S = S; sortVecPair(T, W); for (int i = 0; i < N; i++) { if (W[i] < X) continue; long long a = T[i]; for (int j = 1; j < M; j++) { long long b = a + 1LL * (_S[j] - _S[j - 1]) * W[i]; for (int k = 0; k < SS[j].size(); k++) { if (SS[j][k].first < a && SS[j][k].second > b) b = SS[j][k].second; } SS[j].push_back(std::make_pair(a, b)); a = b; } } for (int j = 1; j < M; j++) { std::sort(SS[j].begin(), SS[j].end(), sort2()); std::vector<std::pair<long long, long long>> sorted; long long b = 0; for (int i = 0; i < SS[j].size(); i++) { if (b < SS[j][i].second) { b = SS[j][i].second; sorted.push_back(std::make_pair(SS[j][i].first, b)); } } SS[j] = sorted; } return; } long long arrival_time(long long Y) { long long a = Y; for (int j = 1; j < _M; j++) { long long b = a + 1LL * (_S[j]-_S[j-1]) * _X; if (SS[j].size() > 0 && SS[j][0].first < a) { int l = 0, r = SS[j].size(); while (l < r) { int m = (l + r + 1) / 2; if (m == SS[j].size()) { break; } else if (SS[j][m].first < a) { l = m; } else { r = m - 1; } } if (l < SS[j].size() && b < SS[j][l].second) b = SS[j][l].second; } a = b; } return a; }

Compilation message (stderr)

overtaking.cpp: In function 'void sortVecPair(std::vector<long long int>&, std::vector<int>&)':
overtaking.cpp:28:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |     for (int i = 0; i < vecA.size(); i++)
      |                     ~~^~~~~~~~~~~~~
overtaking.cpp:39:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |     for (int i = 0; i < vecC.size(); i++)
      |                     ~~^~~~~~~~~~~~~
overtaking.cpp: In function 'void init(int, int, std::vector<long long int>, std::vector<int>, int, int, std::vector<int>)':
overtaking.cpp:68:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |             for (int k = 0; k < SS[j].size(); k++)
      |                             ~~^~~~~~~~~~~~~~
overtaking.cpp:86:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   86 |         for (int i = 0; i < SS[j].size(); i++)
      |                         ~~^~~~~~~~~~~~~~
overtaking.cpp: In function 'long long int arrival_time(long long int)':
overtaking.cpp:115:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  115 |                 if (m == SS[j].size())
      |                     ~~^~~~~~~~~~~~~~~
overtaking.cpp:129:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  129 |             if (l < SS[j].size() && b < SS[j][l].second)
      |                 ~~^~~~~~~~~~~~~~
#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...