Submission #1021746

#TimeUsernameProblemLanguageResultExecution timeMemory
1021746induwara16Arranging Shoes (IOI19_shoes)C++17
Compilation error
0 ms0 KiB
#include "shoes.h" #include <bits/stdc++.h> using namespace std; #define itr(a) a.begin(), a.end() typedef vector<int> vi; typedef unordered_map<int, int> mii; void move(mii &chain, mii &rev, int a, int b) { chain[rev[a]] = chain[a]; rev[chain[a]] = rev[a]; chain[a] = chain[b]; rev[chain[b]] = a; chain[b] = a; rev[a] = b; } int cost(mii chain, int a, int b, int c = 0) { if (a == b) return c; c++; return cost(chain, chain[a], b, c); } long long count_swaps(vi s) { int n = s.size(), l = 0; long long c = 0; mii chain, rev; unordered_map<int, priority_queue<int>> ref; chain[-1] = 0; rev[0] = -1; for (int i = 0; i < n; i++) { if (i != n - 1) { chain[i] = i + 1; rev[i + 1] = i; } ref[s[i]].push(-i); } for (int i = 0; i < n / 2; i++) { int ln = s[l], li = l, cst = 0; li = -ref[-ln].top(); ref[ln].pop(); ref[-ln].pop(); if (ln < 0) { c += cost(chain, l, li) - 1; move(chain, rev, li, l); l = chain[li]; } else { c += cost(chain, l, li); move(chain, rev, li, rev[l]); l = chain[l]; } } return c; }#include "shoes.h" #include <bits/stdc++.h> using namespace std; #define itr(a) a.begin(), a.end() typedef vector<int> vi; typedef unordered_map<int, int> mii; void move(mii &chain, mii &rev, int a, int b) { chain[rev[a]] = chain[a]; rev[chain[a]] = rev[a]; chain[a] = chain[b]; rev[chain[b]] = a; chain[b] = a; rev[a] = b; } int cost(mii chain, int a, int b, int c = 0) { if (a == b) return c; c++; return cost(chain, chain[a], b, c); } long long count_swaps(vi s) { int n = s.size(), l = 0; long long c = 0; mii chain, rev; unordered_map<int, priority_queue<int>> ref; chain[-1] = 0; rev[0] = -1; for (int i = 0; i < n; i++) { if (i != n - 1) { chain[i] = i + 1; rev[i + 1] = i; } ref[s[i]].push(-i); } for (int i = 0; i < n / 2; i++) { int ln = s[l], li = l, cst = 0; li = -ref[-ln].top(); ref[ln].pop(); ref[-ln].pop(); if (ln < 0) { c += cost(chain, l, li) - 1; move(chain, rev, li, l); l = chain[li]; } else { c += cost(chain, l, li); move(chain, rev, li, rev[l]); l = chain[l]; } } return c; }

Compilation message (stderr)

shoes.cpp:76:2: error: stray '#' in program
   76 | }#include "shoes.h"
      |  ^
shoes.cpp: In function 'long long int count_swaps(vi)':
shoes.cpp:55:26: warning: unused variable 'cst' [-Wunused-variable]
   55 |   int ln = s[l], li = l, cst = 0;
      |                          ^~~
shoes.cpp: At global scope:
shoes.cpp:76:3: error: 'include' does not name a type
   76 | }#include "shoes.h"
      |   ^~~~~~~
shoes.cpp:85:6: error: redefinition of 'void move(mii&, mii&, int, int)'
   85 | void move(mii &chain, mii &rev, int a, int b)
      |      ^~~~
shoes.cpp:10:6: note: 'void move(mii&, mii&, int, int)' previously defined here
   10 | void move(mii &chain, mii &rev, int a, int b)
      |      ^~~~
shoes.cpp:97:5: error: redefinition of 'int cost(mii, int, int, int)'
   97 | int cost(mii chain, int a, int b, int c = 0)
      |     ^~~~
shoes.cpp:22:5: note: 'int cost(mii, int, int, int)' previously defined here
   22 | int cost(mii chain, int a, int b, int c = 0)
      |     ^~~~
shoes.cpp:106:11: error: redefinition of 'long long int count_swaps(vi)'
  106 | long long count_swaps(vi s)
      |           ^~~~~~~~~~~
shoes.cpp:31:11: note: 'long long int count_swaps(vi)' previously defined here
   31 | long long count_swaps(vi s)
      |           ^~~~~~~~~~~
shoes.cpp: In function 'long long int count_swaps(vi)':
shoes.cpp:130:26: warning: unused variable 'cst' [-Wunused-variable]
  130 |   int ln = s[l], li = l, cst = 0;
      |                          ^~~