Submission #866674

# Submission time Handle Problem Language Result Execution time Memory
866674 2023-10-26T16:36:09 Z sofija6 Password (RMI18_password) C++14
10 / 100
224 ms 952 KB
#include <bits/stdc++.h>

using namespace std;

int query(string str);

string guess(int n, int s)
{
    string ans="";
    vector<pair<int,int> > cnt;
    for (int i=0;i<s;i++)
    {
        string S="";
        for (int j=1;j<=n;j++)
            S+=(char)(i+'a');
        cnt.push_back({query(S),i});
    }
    sort(cnt.begin(),cnt.end(),greater<pair<int,int> >());
    for (int i=1;i<=cnt[0].first;i++)
        ans+=(char)(cnt[0].second+'a');
    int cur=1;
    while (ans.size()!=n)
    {
        int p=0;
        for (int i=1;i<=cnt[cur].first;i++)
        {
            while (true)
            {
                string S="";
                for (int j=0;j<p;j++)
                    S+=ans[j];
                S+=(char)(cnt[cur].second+'a');
                for (int j=p;j<ans.size();j++)
                    S+=ans[j];
                if (query(S)==S.size())
                {
                    ans=S;
                    break;
                }
                else
                    p++;
            }
        }
        cur++;
    }
    return ans;
}

Compilation message

password.cpp: In function 'std::string guess(int, int)':
password.cpp:22:22: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   22 |     while (ans.size()!=n)
      |            ~~~~~~~~~~^~~
password.cpp:33:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |                 for (int j=p;j<ans.size();j++)
      |                              ~^~~~~~~~~~~
password.cpp:35:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |                 if (query(S)==S.size())
      |                     ~~~~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Guessed the password with 87 queries.
2 Correct 1 ms 600 KB Guessed the password with 156 queries.
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Guessed the password with 72 queries.
2 Runtime error 1 ms 600 KB Execution killed with signal 13
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 60 ms 700 KB Guessed the password with 9016 queries.
2 Correct 81 ms 460 KB Guessed the password with 11748 queries.
3 Correct 153 ms 952 KB Guessed the password with 20616 queries.
4 Runtime error 224 ms 696 KB Execution killed with signal 13
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Guessed the password with 87 queries.
2 Correct 1 ms 600 KB Guessed the password with 156 queries.
3 Correct 1 ms 344 KB Guessed the password with 72 queries.
4 Runtime error 1 ms 600 KB Execution killed with signal 13
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Guessed the password with 87 queries.
2 Correct 1 ms 600 KB Guessed the password with 156 queries.
3 Correct 1 ms 344 KB Guessed the password with 72 queries.
4 Runtime error 1 ms 600 KB Execution killed with signal 13
5 Halted 0 ms 0 KB -