Submission #643143

# Submission time Handle Problem Language Result Execution time Memory
643143 2022-09-21T09:55:05 Z TimDee Password (RMI18_password) C++17
30 / 100
4 ms 208 KB
#include <bits/stdc++.h>
using namespace std;
#define forn(i,n) for (int i=0; i<n; ++i)

int query(string s);

string guess(int n, int c) {

  if (c==2) {
    string A(n,'a'), B(n,'b');
    int a=query(A),b=query(B);
    string ans;
    int added=0;
    for (int i=a; i>=0; --i) {
      string s;
      for (int j=0; j<i; ++j) s+='a';
      for (int j=i; j<n; ++j) s+='b';
      int x=query(s);
      for (int j=0; j<x-added-i; ++j) ans+='b';
      ans+='a';
      added=x-i;
    }
    ans.pop_back();
    reverse(ans.begin(), ans.end());
    return ans;
  }
  if (c==3) {
    string A(n,'a'), B(n,'b'), C(n,'c');
    int a=query(A),b=query(B),c=query(C);
    string ans;
    int addedb=0,addedc=0;
    for (int i=a; i>=0; --i) {
      string s;
      for (int j=0; j<i; ++j) s+='a';
      for (int j=i; j<n; ++j) s+='b';
      int x=query(s)-i-addedb;
      s.clear();
      for (int j=0; j<i; ++j) s+='a';
      for (int j=i; j<n; ++j) s+='c';
      int y=query(s)-i-addedc;
      
      string tmp(i,'a');
      int added=0;
    if (y) {
      for (int j=x; j>=0; --j) {
        string s=tmp;
        for (int k=0; k<j; ++k) s+='b';
        for (int k=0; k<y; ++k) s+='c';
        int v=query(s)-i-j-added;
        for (int k=0; k<v; ++k) {
          ans+='c'; addedc++; added++;
        }
        ans+='b';
        addedb++;
      } 
      if (ans.size()) {ans.pop_back(); --addedb;}
    }
      else for(int k=0; k<x; ++k) {ans+='b'; addedb++;}
      
      ans.push_back('a');
    }
    if (ans.size()) ans.pop_back();
    reverse(ans.begin(), ans.end());
    return ans;
  }

  if (c==4) {
    string A(n,'a'), B(n,'b'), C(n,'c'), D(n,'d');
    int a=query(A),b=query(B),c=query(C),d=query(D);
    string ans;
    int addedb=0,addedc=0,addedd=0;
    for (int i=a; i>=0; --i) {
      string s; forn(j,i) s+='a';
      string t=s; forn(j,n-i) t+='b';
      int x=query(t)-i-addedb;
      t=s; forn(j,n-i) t+='c';
      

      for (int j=x; j>=0; --j) {

        string t=s;
        forn(k,j) t+='b';
        string p=t; forn(k,n-i-j) p+='c';
        int y=query(p)-i-j-addedc;

        for (int k=y; k>=0; --k) {
          string p=t;
          forn(l,k) p+='c';
          string q=p; forn(l,n-i-j-k) q+='d';
          int z=query(q)-i-j-k-addedd;
          forn(l,z) {
            ans+='d'; ++addedd;
          }
          ans+='c'; ++addedc;
        }
        ans.pop_back(); --addedc;
        ans+='b'; ++addedb;

      }
      ans.pop_back(); --addedb;
      ans+='a';

    }
    ans.pop_back();
    reverse(ans.begin(), ans.end());
    return ans;
  }

  if (n<=c && c<=26) {
    string ans(n,'.');
    for (char i='a'; i<'a'+c; ++i) {
      int x=0;
      for (char j='a'; j<'a'+c; ++j) {
        if (j==i) continue;
        string s;
        s+=i; s+=j;
        int q=query(s);
        x+=q-1;
      }
      if (x<0) continue;
      ans[n-1-x]=i;
    }
    int paiu=1;
    for (auto x:ans) paiu&=x!='.';
    if (paiu) return ans;
  }
  return "abc";
}

Compilation message

password.cpp: In function 'std::string guess(int, int)':
password.cpp:11:20: warning: unused variable 'b' [-Wunused-variable]
   11 |     int a=query(A),b=query(B);
      |                    ^
password.cpp:29:20: warning: unused variable 'b' [-Wunused-variable]
   29 |     int a=query(A),b=query(B),c=query(C);
      |                    ^
password.cpp:29:31: warning: unused variable 'c' [-Wunused-variable]
   29 |     int a=query(A),b=query(B),c=query(C);
      |                               ^
password.cpp:69:20: warning: unused variable 'b' [-Wunused-variable]
   69 |     int a=query(A),b=query(B),c=query(C),d=query(D);
      |                    ^
password.cpp:69:31: warning: unused variable 'c' [-Wunused-variable]
   69 |     int a=query(A),b=query(B),c=query(C),d=query(D);
      |                               ^
password.cpp:69:42: warning: unused variable 'd' [-Wunused-variable]
   69 |     int a=query(A),b=query(B),c=query(C),d=query(D);
      |                                          ^
# Verdict Execution time Memory Grader output
1 Correct 2 ms 208 KB Guessed the password with 211 queries.
2 Correct 4 ms 208 KB Guessed the password with 507 queries.
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Guessed the password with 28 queries.
2 Correct 2 ms 208 KB Guessed the password with 114 queries.
3 Correct 1 ms 208 KB Guessed the password with 27 queries.
4 Correct 2 ms 208 KB Guessed the password with 136 queries.
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 208 KB Returned early from guess() after 1 queries.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 208 KB Guessed the password with 211 queries.
2 Correct 4 ms 208 KB Guessed the password with 507 queries.
3 Correct 0 ms 208 KB Guessed the password with 28 queries.
4 Correct 2 ms 208 KB Guessed the password with 114 queries.
5 Correct 1 ms 208 KB Guessed the password with 27 queries.
6 Correct 2 ms 208 KB Guessed the password with 136 queries.
7 Incorrect 0 ms 208 KB Returned early from guess() after 1 queries.
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 208 KB Guessed the password with 211 queries.
2 Correct 4 ms 208 KB Guessed the password with 507 queries.
3 Correct 0 ms 208 KB Guessed the password with 28 queries.
4 Correct 2 ms 208 KB Guessed the password with 114 queries.
5 Correct 1 ms 208 KB Guessed the password with 27 queries.
6 Correct 2 ms 208 KB Guessed the password with 136 queries.
7 Incorrect 0 ms 208 KB Returned early from guess() after 1 queries.
8 Halted 0 ms 0 KB -