제출 #309721

#제출 시각아이디문제언어결과실행 시간메모리
309721lukameladzeCombo (IOI18_combo)C++14
컴파일 에러
0 ms0 KiB
#include <cstdio> #include <cstdlib> #include <algorithm> # include <iostream> #include <string> using namespace std; namespace { const int MAX_N = 2000; const 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 int press(std::string p) { cout<<p<<endl<<endl; if (++num_moves > MAX_NUM_MOVES) { wrong_answer("too many moves"); } int len = p.length(); if (len > 4 * N) { cout<<p<<endl; wrong_answer("invalid press"); } for (int i = 0; i < len; ++i) { if (p[i] != 'A' && p[i] != 'B' && p[i] != 'X' && p[i] != 'Y') { cout<<p<<endl; 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); } return coins; } std::string guess_sequence(int N) { std::string pref; std::string p="AB"; int c=press(p); if (c) { p="A"; c=press(p); if (c) pref="A"; else pref="B"; } else { p="X"; c=press(p); if (c) pref="X"; else pref="Y"; } if (pref=="A") { while (pref.size()<N-1) { cout<<pref<<" 1"<<endl; p=pref+"B"+pref+"XY"+pref+"XB"+pref+"XX"; c=press(p); if(c==pref.size()+1) { pref+="B"; } else if (c==pref.size()+2) { pref+="X"; } else pref+="Y"; } c=press(pref+"X"); if (c==N) pref+="X"; else { c=press(pref+"Y"); if (c==N) pref+="Y"; if (pref.size()!=N) pref+="B"; } } if (pref=="X") { while (pref.size()<N-1) { // cout<<pref<<" 1"<<endl; p=pref+"B"+pref+"AY"+pref+"AB"+pref+"AA"; c=press(p); if(c==pref.size()+1) { pref+="B"; } else if (c==pref.size()+2) { pref+="A"; } else pref+="Y"; } c=press(pref+"A"); if (c==N) pref+="A"; else { c=press(pref+"Y"); if (c==N) pref+="Y"; if (pref.size()!=N) pref+="B"; } } if (pref=="B") { while (pref.size()<N-1) { p=pref+"A"+pref+"XY"+pref+"XA"+pref+"XX"; c=press(p); if(c==pref.size()+1) { pref+="A"; } else if (c==pref.size()+2) { pref+="X"; } else pref+="Y"; } c=press(pref+"X"); if (c==N) pref+="X"; else { c=press(pref+"Y"); if (c==N) pref+="Y"; if (pref.size()!=N) pref+="A"; } } if (pref=="Y") { while (pref.size()<N-1) { p=pref+"B"+pref+"XA"+pref+"XB"+pref+"XX"; c=press(p); if(c==pref.size()+1) { pref+="B"; } else if (c==pref.size()+2) { pref+="X"; } else pref+="A"; } // cout<<pref<<endl; c=press(pref+"X"); if (c==N) pref+="X"; else { c=press(pref+"A"); if (c==N) pref+="A"; if (pref.size()!=N) pref+="B"; } } return pref; } 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); return 0; }

컴파일 시 표준 에러 (stderr) 메시지

combo.cpp: In function 'std::string guess_sequence(int)':
combo.cpp:78:29: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   78 |   {       while (pref.size()<N-1)
      |                  ~~~~~~~~~~~^~~~
combo.cpp:83:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   83 |           if(c==pref.size()+1)
      |              ~^~~~~~~~~~~~~~~
combo.cpp:88:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   88 |           if (c==pref.size()+2)
      |               ~^~~~~~~~~~~~~~~
combo.cpp:102:24: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  102 |         if (pref.size()!=N)
      |             ~~~~~~~~~~~^~~
combo.cpp:108:26: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  108 |        while (pref.size()<N-1)
      |               ~~~~~~~~~~~^~~~
combo.cpp:113:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  113 |           if(c==pref.size()+1)
      |              ~^~~~~~~~~~~~~~~
combo.cpp:118:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  118 |           if (c==pref.size()+2)
      |               ~^~~~~~~~~~~~~~~
combo.cpp:132:24: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  132 |         if (pref.size()!=N)
      |             ~~~~~~~~~~~^~~
combo.cpp:138:26: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  138 |        while (pref.size()<N-1)
      |               ~~~~~~~~~~~^~~~
combo.cpp:142:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  142 |           if(c==pref.size()+1)
      |              ~^~~~~~~~~~~~~~~
combo.cpp:147:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  147 |           if (c==pref.size()+2)
      |               ~^~~~~~~~~~~~~~~
combo.cpp:162:24: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  162 |         if (pref.size()!=N)
      |             ~~~~~~~~~~~^~~
combo.cpp:168:26: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  168 |        while (pref.size()<N-1)
      |               ~~~~~~~~~~~^~~~
combo.cpp:172:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  172 |           if(c==pref.size()+1)
      |              ~^~~~~~~~~~~~~~~
combo.cpp:177:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  177 |           if (c==pref.size()+2)
      |               ~^~~~~~~~~~~~~~~
combo.cpp:192:24: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  192 |         if (pref.size()!=N)
      |             ~~~~~~~~~~~^~~
/usr/bin/ld: /tmp/cc7CE5NR.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/ccrRYTGT.o:combo.cpp:(.text+0xf0): first defined here
/usr/bin/ld: /tmp/cc7CE5NR.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccrRYTGT.o:combo.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status