Submission #1215109

#TimeUsernameProblemLanguageResultExecution timeMemory
1215109lizi14Combo (IOI18_combo)C++20
Compilation error
0 ms0 KiB
#include <cstdio> #include <cstdlib> #include <algorithm> #include <string> #include "combo.h" using namespace std; string guess_sequence(int N) { int d[4]={0,0,0,0}; char p[4]={'A','B','X','Y'}; string s_1,s_2,s_3,s_4; string sa=""; int coins = press("AB"); if(coins==1){ coins=press("A"); if(coins==1){ d[0]=1; sa+="A"; } else{ d[1]=1; sa+="B"; } } else{ coins=press("X"); if(coins==1){ d[2]=1; sa+="X"; } else{ d[3]=1; sa+="Y"; } } if(d[3]==1){ s_1="A"; s_2="BA"; s_3="BB"; s_4="BX"; } else if(d[2]==1){ s_1="A"; s_2="BA"; s_3="BB"; s_4="BY"; } else if(d[0]==1){ s_1="B"; s_2="XB"; s_3="XX"; s_4="XY"; } else{ s_1="A"; s_2="XA"; s_3="XX"; s_4="XY"; } while(sa.size()<N-1){ string w=""; for(int i=1; i<=4; i++){ w+=sa; if(i%4==1){ w+=s_1; } else if(i%4==2){ w+=s_2; } else if(i%4==3){ w+=s_3; } else w+=s_4; } coins=press(w); if(coins==sa.size()+1){ sa+=s_1[0]; } else if(coins==sa.size()){ sa+=s_4[1]; } else sa+=s_2[0]; } int k=0; for(int i=0; i<4; i++){ if(k==2)break; if(d[i]==0){ string w=sa; w+=p[i]; coins=press(w); k++; if(coins==N){ sa+=p[i]; return sa; } else d[i]=1; } } for(int i=0; i<4; i++){ if(d[i]==0){ sa+=p[i]; } } return sa; } 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 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); } return coins; } 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; }

Compilation message (stderr)

/usr/bin/ld: /tmp/ccyWBHuc.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/cc9423Qt.o:combo.cpp:(.text+0x30): first defined here
/usr/bin/ld: /tmp/ccyWBHuc.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/cc9423Qt.o:combo.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status