Submission #228120

#TimeUsernameProblemLanguageResultExecution timeMemory
228120Romario8Combo (IOI18_combo)C++17
Compilation error
0 ms0 KiB
#include<bits/stdc++.h> #define rep(i,a,b) for(int i=a;i<b;i++) #define rrep(i,a,b) for(int i=a;i>=b;i--) #define pb push_back #define rl "\n" #define ll long long using namespace std; 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); } 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; } string guess_sequence(int N) { int n=N; string ans=""; string g1="XY",g2="AB"; if(press(g1)==0)swap(g1,g2); string s1=""; s1+=g1[0]; string s2=""; s2+=g1[1]; string s3=""; char a='A',b='B',x='X',y='Y'; string p1=""; if(press(s1)==1)ans+=s1[0]; else ans+=s2[0]; if(ans[0]==a)swap(a,y); else if(ans[0]==b)swap(b,y); else if(ans[0]==x)swap(x,y); s1=ans+a; s2=ans+b; s3=ans+x; p1=s1+a+s1+b+s1+x+s2; while(ans.size()!=n-1) { int pr=press(p1); if(pr==ans.size()+2) { ans=s1; } else if(pr==ans.size()+1) { ans=s2; } else { ans=s3; } s1=ans+a; s2=ans+b; s3=ans+x; p1=s1+a+s1+b+s1+x+s2; } string res=""; res+=ans+a+ans+b; int pr1=press(res); if(pr1==n) { res=ans+a; pr1=press(res); if(pr1==n) { ans+=a; } else ans+=b; return ans; } else { ans+=x; return ans; } }

Compilation message (stderr)

combo.cpp: In function 'std::string guess_sequence(int)':
combo.cpp:68:21: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   68 |     while(ans.size()!=n-1)
      |           ~~~~~~~~~~^~~~~
combo.cpp:71:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |         if(pr==ans.size()+2)
      |            ~~^~~~~~~~~~~~~~
combo.cpp:75:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   75 |         else if(pr==ans.size()+1)
      |                 ~~^~~~~~~~~~~~~~
/usr/bin/ld: /tmp/cc5PNZq7.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/ccIrnwu4.o:combo.cpp:(.text+0xf0): first defined here
collect2: error: ld returned 1 exit status