Submission #588139

#TimeUsernameProblemLanguageResultExecution timeMemory
588139evenvalueCombo (IOI18_combo)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; template <typename T> using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>; template <typename T> using min_heap = priority_queue<T, vector<T>, greater<T>>; template <typename T> using max_heap = priority_queue<T, vector<T>, less<T>>; using int64 = long long; using ld = long double; constexpr int kInf = 1e9 + 10; constexpr int64 kInf64 = 1e15 + 10; constexpr int kMod = 1e9 + 7; string ans = "A"; int moves = 0; void check(const string &guess, bool final = false) { moves++; if (moves > ans.length() + 2 + 1) { cout << "too many moves for " << ans << '\n'; exit(0); } else if (guess.size() > 4 * (int)ans.size()) { cout << "invalid press"; exit(0); } else if (final and guess != ans) { cout << "wrong answer"; cout << "Your guess: " << guess << '\n'; exit(0); } else if (final) { cout << "Got correct answer in " << moves - 1 << " moves\n"; return; } else { return; } } int press(const string &guess) { check(guess); for (int len = ans.length(); len > 0; len--) { for (int i = 0; i + len <= guess.size(); i++) { if (guess.substr(i, len) == ans.substr(0, len)) { return len; } } } return 0; // cout << guess << '\n'; // int x; // cin >> x; // return x; } string convert(string guess) { for (char &c : guess) { c = (c == '1' ? 'A' : c); c = (c == '2' ? 'B' : c); c = (c == '3' ? 'X' : c); c = (c == '4' ? 'Y' : c); } return guess; } int call_press(string s) { return press(convert(std::move(s))); } string guess_sequence(const int N) { string s = "-"; if (const int x = call_press("12"); x == 0) { s[0] = (call_press("3") ? '3' : '4'); } else { s[0] = (call_press("1") ? '1' : '2'); } if (N == 1) return convert(s); string choices; for (char c = '1'; c <= '4'; c++) { if (c == s[0]) continue; choices += c; } for (int i = 1; i < N - 1; i++) { string guess; for (int j = 0; j < 3; j++) { guess += s + choices[0] + choices[j]; } guess += s + choices[1]; if (const int x = call_press(guess); x == s.size()) { s.push_back(choices[2]); } else if (x == s.size() + 1) { s.push_back(choices[1]); } else { s.push_back(choices[0]); } } if (call_press(s + choices[0]) == N) { s += choices[0]; } else if (call_press(s + choices[1]) == N) { s += choices[1]; } else { s += choices[2]; } return convert(s); } void reset() { ans = ""; moves = 0; } int main() { random_device rd; uniform_int_distribution<int> u(1, 4); for (int len = 1000; len < 1001; len++) { string s(len, '-'); for (int i = 0; i < len; i++) { s[i] = u(rd) + '0'; } ans = convert(s); guess_sequence(ans.length()); reset(); } }

Compilation message (stderr)

combo.cpp: In function 'void check(const string&, bool)':
combo.cpp:29:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |   if (moves > ans.length() + 2 + 1) {
      |       ~~~~~~^~~~~~~~~~~~~~~~~~~~~~
combo.cpp:32:27: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   32 |   } else if (guess.size() > 4 * (int)ans.size()) {
      |              ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
combo.cpp: In function 'int press(const string&)':
combo.cpp:50:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |     for (int i = 0; i + len <= guess.size(); i++) {
      |                     ~~~~~~~~^~~~~~~~~~~~~~~
combo.cpp: In function 'std::string guess_sequence(int)':
combo.cpp:99:44: warning: comparison of integer expressions of different signedness: 'const int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   99 |     if (const int x = call_press(guess); x == s.size()) {
      |                                          ~~^~~~~~~~~~~
combo.cpp:101:18: warning: comparison of integer expressions of different signedness: 'const int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  101 |     } else if (x == s.size() + 1) {
      |                ~~^~~~~~~~~~~~~~~
/usr/bin/ld: /tmp/ccY6CNih.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/cc0x1Hwi.o:combo.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status