Submission #755943

#TimeUsernameProblemLanguageResultExecution timeMemory
755943vjudge1Password (RMI18_password)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; #define vi vector<int> #define vl vector<long long> #define vii vector<pair<int,int>> #define vll vector<pair<long long,long long>> #define pb push_back #define ll long long #define ld long double #define nl '\n' #define boost ios::sync_with_stdio(false) #define mp make_pair #define se second #define fi first #define fore(i, y) for(ll i = 0; i < y; i++) #define forr(i,x,y) for(int i = x;i<=y;i++) #define forn(i,y,x) for(ll i = y; i >= x; i--) #define all(v) v.begin(),v.end() #define sz(v) v.size() #define clr(v,k) memset(v,k,sizeof(v)) #define rall(v) v.rbegin() , v.rend() #define pii pair<int,int> #define pll pair<ll , ll> const ll MOD = 1e9 + 7; const ll INF = 1e18 + 1; ll gcd(ll a , ll b) {return b ? gcd(b , a % b) : a ;} // greatest common divisor (PGCD) ll lcm(ll a , ll b) {return a * (b / gcd(a , b));} // least common multiple (PPCM) // HERE IS THE SOLUTION vector<vector<string>> possible(5); void brute() { forr(i , 'a' , 'd') { string s = ""; s+=i; forr(j , 'a' , 'd') { s+= j; possible[2].pb(s); forr(k , 'a' , 'd') { s+= k; possible[3].pb(s); forr(l , 'a' , 'd') { s+= l; possible[4].pb(s); s.erase(s.begin() + 3); } s.erase(s.begin() + 2); } s.erase(s.begin() + 1); } s.erase(s.begin()); } } int query(string str) { if(str == "abcd")return 4; if(str == "abcdaaaa")return 8; return 0; } string guess(int n,int s ) { brute(); string t = ""; do { if(sz(t) + s > n) { if(sz(t) + s - 1 == n) { for(auto str : possible[s-1]) { if(query(t + str) == sz(t) + s - 1) { t = t+ str; break; } } } else if(sz(t) + s - 2 == n) { for(auto str : possible[s-2]) { if(query(t + str) == sz(t) + s-2) { t = t + str; break; } } } } for(auto str : possible[s]) { if(query(t + str) == sz(t) + s) { t = t+str; break; } } } while(query(t) != n); return t; }

Compilation message (stderr)

password.cpp: In function 'std::string guess(int, int)':
password.cpp:74:22: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   74 |         if(sz(t) + s > n)
      |                      ^
password.cpp:76:30: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   76 |             if(sz(t) + s - 1 == n)
      |                              ^
password.cpp:80:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   80 |                     if(query(t + str) == sz(t) + s - 1)
      |                        ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
password.cpp:87:36: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   87 |             else if(sz(t) + s  - 2 == n)
      |                                    ^
password.cpp:91:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   91 |                     if(query(t + str) == sz(t) + s-2)
      |                        ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
password.cpp:101:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  101 |             if(query(t + str) == sz(t) + s)
      |                ~~~~~~~~~~~~~~~^~~~~~~~~~~~
/usr/bin/ld: /tmp/ccjaQNLZ.o: in function `query(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)':
grader.cpp:(.text+0x80): multiple definition of `query(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)'; /tmp/ccJNQ6KW.o:password.cpp:(.text+0x210): first defined here
collect2: error: ld returned 1 exit status