답안 #1117348

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1117348 2024-11-23T10:54:37 Z Unconcurrent Password (RMI18_password) C++17
10 / 100
976 ms 704 KB
// (C) Sologub Radu
#include <iostream>
#include <cmath>
#include <vector>
#include <fstream>
#include <algorithm>
#include <iomanip> // for std::setw and std::setfill
#include <map>
 
using namespace std;
 
 
int query( string str) ;
string guess(int len, int alphabet){
    string guess = "a";
    // first char guess
    while(query(guess) != 1){
        guess[0]++;
    }
 
    forward_looking:
    // forward looking
    char forwardGuess = 'a';
    while(forwardGuess < 'a' + alphabet && query(guess + forwardGuess) < guess.size() + 1){
        forwardGuess++;
    }
 
    if(forwardGuess >= 'a' + alphabet){
        // failed forward look, skip;
    }else{
        // success
        guess = guess + forwardGuess;
        // cout << guess << endl;
        goto forward_looking;
    }
 
 
    int backInsertIndex = guess.size() - 1;
    back_inserter:
    if(guess.size() == len){
        return guess;
    }
    
    string backGuess = "a";
    backGuess[0]--;
    
    string guessTry;
    do{
        guessTry = guess;
        backGuess[0]++;
        guessTry.insert(backInsertIndex, backGuess);
        // cout << "guessTry = " << guessTry << endl;
    }while(backGuess[0] < 'a' + alphabet
        && query(guessTry) < guess.size() + 1);
    
    if(backGuess[0] >= 'a' + alphabet){
        // failed back insert at index;
        backInsertIndex --;
        if(backInsertIndex < 0){
            backInsertIndex = guess.size() - 1;
        }
    }else{
        // success
        // backInsertIndex --;
        guess = guess.insert(backInsertIndex, backGuess);
        // cout << guess << endl;
    }
    goto back_inserter;
}

Compilation message

password.cpp: In function 'std::string guess(int, int)':
password.cpp:24:72: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |     while(forwardGuess < 'a' + alphabet && query(guess + forwardGuess) < guess.size() + 1){
      |                                            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
password.cpp:40:21: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   40 |     if(guess.size() == len){
      |        ~~~~~~~~~~~~~^~~~~~
password.cpp:54:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |         && query(guessTry) < guess.size() + 1);
      |            ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 336 KB Guessed the password with 420 queries.
2 Correct 15 ms 336 KB Guessed the password with 1012 queries.
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 336 KB Guessed the password with 124 queries.
2 Correct 9 ms 348 KB Guessed the password with 441 queries.
3 Runtime error 4 ms 444 KB Execution killed with signal 13
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 976 ms 704 KB Could not guess the password with 50000 queries.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 336 KB Guessed the password with 420 queries.
2 Correct 15 ms 336 KB Guessed the password with 1012 queries.
3 Correct 2 ms 336 KB Guessed the password with 124 queries.
4 Correct 9 ms 348 KB Guessed the password with 441 queries.
5 Runtime error 4 ms 444 KB Execution killed with signal 13
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 336 KB Guessed the password with 420 queries.
2 Correct 15 ms 336 KB Guessed the password with 1012 queries.
3 Correct 2 ms 336 KB Guessed the password with 124 queries.
4 Correct 9 ms 348 KB Guessed the password with 441 queries.
5 Runtime error 4 ms 444 KB Execution killed with signal 13
6 Halted 0 ms 0 KB -