Submission #915602

#TimeUsernameProblemLanguageResultExecution timeMemory
915602MatjazTeleporters (IOI08_teleporters)C++14
0 / 100
193 ms65536 KiB
// // IOI2008Teleporters.cpp // // // Created by Matjaz Leonardis on 24/01/2024. // #include <iostream> #include <vector> #include <algorithm> using namespace std; int N,M; int main(){ cin >> N >> M; vector<pair<int,int> > X(4*N); vector<int> next(4*N, -1); for (int i=0;i<N;i++){ int W,E; X.push_back(make_pair(W, 4 * i)); X.push_back(make_pair(W, 4 * i + 1)); X.push_back(make_pair(E, 4 * i + 2)); X.push_back(make_pair(E, 4 * i + 3)); next[4 * i] = 4 * i + 3; next[4 * i + 2] = 4 * i + 1; } sort(X.begin(), X.end()); for (int i=0;i<X.size() - 1; i++){ if (next[X[i].second] == -1) next[X[i].second] = X[i + 1].second; } int jumps = 0; vector<int> cycle; vector<bool> visited(4 * N, false); for (int i=0;i<X.size();i++){ if (visited[X[i].second]) continue; int current = X[i].second; int l = 0; visited[X[i].second] = true; while (next[current] != X[i].second && next[current] != -1){ l++; current = next[current]; visited[current] = true; } if (i == 0){ jumps += l; } else cycle.push_back(l); } sort(cycle.rbegin(), cycle.rend()); for (int i=0;i<M;i++){ if (i >= cycle.size()) jumps += 4; else jumps += cycle[i] + 3; } cout << jumps << endl; return 0; }

Compilation message (stderr)

teleporters.cpp: In function 'int main()':
teleporters.cpp:33:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |     for (int i=0;i<X.size() - 1; i++){
      |                  ~^~~~~~~~~~~~~
teleporters.cpp:43:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |     for (int i=0;i<X.size();i++){
      |                  ~^~~~~~~~~
teleporters.cpp:63:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |         if (i >= cycle.size()) jumps += 4; else
      |             ~~^~~~~~~~~~~~~~~
teleporters.cpp:24:39: warning: 'W' may be used uninitialized in this function [-Wmaybe-uninitialized]
   24 |         X.push_back(make_pair(W, 4 * i));
      |                                       ^
teleporters.cpp:26:43: warning: 'E' may be used uninitialized in this function [-Wmaybe-uninitialized]
   26 |         X.push_back(make_pair(E, 4 * i + 2));
      |                                           ^
#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...
#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...