Submission #285087

#TimeUsernameProblemLanguageResultExecution timeMemory
285087BertedUnscrambling a Messy Bug (IOI16_messy)C++14
100 / 100
3 ms512 KiB
#include <vector> #include <iostream> #include <assert.h> #include "messy.h" using namespace std; string start; vector<int> ans, ans2; void flip(string& s, int i) {s[i] = ((s[i] - '0') ^ 1) + '0';} void ask(int L, int R, string s) { if (L < R) { int M = L + R >> 1; for (int i = M + 1; i <= R; i++) { flip(s, i); add_element(s); flip(s, i); } for (int i = M + 1; i <= R; i++) {flip(s, i);} ask(L, M, s); for (int i = L; i <= R; i++) {flip(s, i);} ask(M + 1, R, s); } } void solve(int L, int R, string s) { if (L < R) { int M = L + R >> 1, idx = L; for (int i = L; i <= R; i++) { flip(s, ans[i]); if (!check_element(s)) {flip(s, ans[i]); swap(ans[i], ans[idx++]);} else {flip(s, ans[i]);} } assert(idx == M + 1); for (int i = M + 1; i <= R; i++) {flip(s, ans[i]);} solve(L, M, s); for (int i = L; i <= R; i++) {flip(s, ans[i]);} solve(M + 1, R, s); } } vector<int> restore_permutation(int n, int w, int r) { for (int i = 0; i < n; i++) {start.push_back('0'); ans.push_back(i); ans2.push_back(0);} ask(0, n - 1, start); compile_set(); solve(0, n - 1, start); for (int i = 0; i < ans.size(); i++) {ans2[ans[i]] = i;} return ans2; }

Compilation message (stderr)

messy.cpp: In function 'void ask(int, int, std::string)':
messy.cpp:18:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   18 |   int M = L + R >> 1;
      |           ~~^~~
messy.cpp: In function 'void solve(int, int, std::string)':
messy.cpp:36:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   36 |   int M = L + R >> 1, idx = L;
      |           ~~^~~
messy.cpp: In function 'std::vector<int> restore_permutation(int, int, int)':
messy.cpp:57:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |  for (int i = 0; i < ans.size(); i++) {ans2[ans[i]] = 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...
#Verdict Execution timeMemoryGrader output
Fetching results...