답안 #201463

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
201463 2020-02-10T16:04:28 Z egekabas Password (RMI18_password) C++14
10 / 100
58 ms 428 KB
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long   ll;
typedef unsigned long long   ull;
typedef long double ld;
typedef pair<ll, ll>    pll;
typedef pair<ull, ull>    pull;
typedef pair<int, int>  pii;
typedef pair<ld, ld>  pld;
int query(string str);
string ans;
void mergesort(ll l, ll r){
    if(l >= r)
        return;
    ll m = (l+r)/2;
    mergesort(l, m);
    mergesort(m+1, r);
    ll it1 = l, it2 = m+1;
    string newans;
    while(it2 <= r){
        while(1){
            string tmp = newans+ans[it2]+ans.substr(it1, m-it1+1);
            if(it1 == m+1 || (query(tmp) == (ll)tmp.size())){
                newans.pb(ans[it2]);
                break;
            }
            newans.pb(ans[it1]);
            ++it1;
        }
        ++it2;
    }
    while(it1 <= m){
        newans.pb(ans[it1]);
        ++it1;
    }
    for(ll i = l; i <= r; ++i){
        ans[i] = newans[i-l];
    }
}
int check(char c, int cnt){
    if(cnt == 0)
        return 1;
    string tmp;
    for(ll i = 0; i < cnt; ++i)
        tmp.pb(c);
    return (query(tmp) == cnt);
}
string guess(int n, int s){
    ll curtot = 0;
    for(ll i = 0; i < s; ++i){
        ll l = 0, r = n-curtot;
        while(l < r){
            ll m = (l+r+1)/2;
            if(check('a'+i, m))
                l = m;
            else
                r = m-1;
        }
        curtot += l;
        while(l--)
            ans.pb('a'+i);
    }
    mergesort(0, n-1);
    if(ans.size() != n)
        while(1);
    return ans;
}

Compilation message

password.cpp: In function 'std::__cxx11::string guess(int, int)':
password.cpp:68:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if(ans.size() != n)
        ~~~~~~~~~~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 376 KB Guessed the password with 90 queries.
2 Correct 6 ms 248 KB Guessed the password with 155 queries.
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 248 KB Guessed the password with 165 queries.
2 Incorrect 7 ms 248 KB Returned early from guess() after 232 queries.
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 58 ms 428 KB Returned early from guess() after 5311 queries.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 376 KB Guessed the password with 90 queries.
2 Correct 6 ms 248 KB Guessed the password with 155 queries.
3 Correct 7 ms 248 KB Guessed the password with 165 queries.
4 Incorrect 7 ms 248 KB Returned early from guess() after 232 queries.
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 376 KB Guessed the password with 90 queries.
2 Correct 6 ms 248 KB Guessed the password with 155 queries.
3 Correct 7 ms 248 KB Guessed the password with 165 queries.
4 Incorrect 7 ms 248 KB Returned early from guess() after 232 queries.
5 Halted 0 ms 0 KB -