Submission #582751

#TimeUsernameProblemLanguageResultExecution timeMemory
582751TimDee콤보 (IOI18_combo)C++14
Compilation error
0 ms0 KiB
#include <cstdio> #include <cstdlib> #include <algorithm> #include <string> //#include "combo.h" namespace { constexpr int MAX_N = 2000; constexpr int MAX_NUM_MOVES = 8000; int N; std::string S; int num_moves; void wrong_answer(const char *MSG) { printf("Wrong Answer: %s\n", MSG); exit(0); } } // namespace #include <bits/stdc++.h> using namespace std; int press(std::string p) { if (++num_moves > MAX_NUM_MOVES) { wrong_answer("too many moves"); } int len = p.length(); if (len > 4 * N) { wrong_answer("invalid press"); } for (int i = 0; i < len; ++i) { if (p[i] != 'A' && p[i] != 'B' && p[i] != 'X' && p[i] != 'Y') { wrong_answer("invalid press"); } } int coins = 0; for (int i = 0, j = 0; i < len; ++i) { if (j < N && S[j] == p[i]) { ++j; } else if (S[0] == p[i]) { j = 1; } else { j = 0; } coins = std::max(coins, j); } //std::cout<<"ask "<<p<<' '<<coins<<'\n'; return coins; } #include <bits/stdc++.h> using namespace std; #define forn(i,n) for (int i=0; i<n; ++i) #define all(a) a.begin(), a.end() #define pb(x) push_back(x) std::string guess_sequence(int N) { int n=N; string s; //forn(i,n) s+='*'; char f; if (press("AB")) { if (press("A")) { f='A'; } else { f='B'; } } else { if (press("X")) { f='X'; } else { f='Y'; } } vector<char> v; if (f!='A') v.pb('A'); if (f!='B') v.pb('B'); if (f!='X') v.pb('X'); if (f!='Y') v.pb('Y'); s+=f; vector<char> Or; while (s.length()!=N) { string p=s; if (Or.size()) p+=Or[0]; p+=v[0]; p+=s; if (Or.size()) p+=Or[0]; p+=v[1]; int x = press(p); if (x==N) { string p=s; if (Or.size()) p+=Or[0]; //p+=v[0]; if (x==press(p+v[0])) return p+v[0]; else return p+v[1]; } if (x==s.length() && x==p.length()/2-1) { if (Or.size()) { s+=Or[0]; Or.clear(); } s+=v[2]; } else if (x>s.length()+Or.size()/2){ if (Or.size()) s+=Or[0]; Or.clear(); Or.pb(v[0]); Or.pb(v[1]); } else if(x>s.length()) { if (Or.size()) s+=Or[0]; s+=v[2]; Or.clear(); } else { if (Or.size()) s+=Or[1]; Or.clear(); } } return s; } int main() { char buffer[MAX_N + 1]; if (scanf("%s", buffer) != 1) { fprintf(stderr, "Error while reading input\n"); exit(1); } S = buffer; N = S.length(); num_moves = 0; std::string answer = guess_sequence(N); if (answer != S) { wrong_answer("wrong guess"); exit(0); } //printf("Accepted: %d\n", num_moves); printf("Accepted: \n"); return 0; }

Compilation message (stderr)

combo.cpp: In function 'std::string guess_sequence(int)':
combo.cpp:83:3: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   83 |   if (f!='A') v.pb('A'); if (f!='B') v.pb('B'); if (f!='X') v.pb('X'); if (f!='Y') v.pb('Y');
      |   ^~
combo.cpp:83:26: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   83 |   if (f!='A') v.pb('A'); if (f!='B') v.pb('B'); if (f!='X') v.pb('X'); if (f!='Y') v.pb('Y');
      |                          ^~
combo.cpp:88:20: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   88 |   while (s.length()!=N) {
      |          ~~~~~~~~~~^~~
combo.cpp:107:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  107 |     if (x==s.length() && x==p.length()/2-1) {
      |         ~^~~~~~~~~~~~
combo.cpp:107:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  107 |     if (x==s.length() && x==p.length()/2-1) {
      |                          ~^~~~~~~~~~~~~~~~
combo.cpp:114:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  114 |     else if (x>s.length()+Or.size()/2){
      |              ~^~~~~~~~~~~~~~~~~~~~~~~
combo.cpp:121:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  121 |     } else if(x>s.length()) {
      |               ~^~~~~~~~~~~
combo.cpp:64:7: warning: unused variable 'n' [-Wunused-variable]
   64 |   int n=N;
      |       ^
/usr/bin/ld: /tmp/ccqLJYyR.o: in function `press(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)':
grader.cpp:(.text+0x0): multiple definition of `press(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)'; /tmp/cckP6MYR.o:combo.cpp:(.text+0xf0): first defined here
/usr/bin/ld: /tmp/ccqLJYyR.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/cckP6MYR.o:combo.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status