Submission #107116

#TimeUsernameProblemLanguageResultExecution timeMemory
107116tictaccatPaint By Numbers (IOI16_paint)C++14
32 / 100
3 ms384 KiB
#include "paint.h"
#include <cstdlib>
#include <bits/stdc++.h>

using namespace std;

std::string solve_puzzle(std::string s, std::vector<int> c) {

    int n = s.size(); int k = c.size();

    string shortest;

    for (int i = 0; i < k; i++) {
        if (i != 0) shortest += '_';
        for (int j = 0; j < c[i]; j++) shortest += 'X';
    }
    
    int minLen = shortest.size();

    while (shortest.size() < n) shortest += '_';

    //cout << shortest << "\n";

    vector<bool> white(n,false), black(n,false);

    for (int pos = 0; pos < n; pos++) {
        //check white
        int j;
        for (j = 0; j <= pos+1; j++) {
            //if (pos == n-1) cout << shortest[pos-j] << "\n";
            if ((j == pos+1 || shortest[pos-j] == '_') && minLen + j <= n) {white[pos] = true; }
            if ((j == pos+1 || shortest[pos-j] == 'X') && minLen + j <= n) black[pos] = true; 
        }
    }

    string ans = s;

    for (int pos = 0; pos < n; pos++) {
        assert(white[pos] || black[pos]);
        if (white[pos] && black[pos]) ans[pos] = '?';
        else if (white[pos]) ans[pos] = '_';
        else if (black[pos]) ans[pos] = 'X';
    }

    return ans;
}

Compilation message (stderr)

paint.cpp: In function 'std::__cxx11::string solve_puzzle(std::__cxx11::string, std::vector<int>)':
paint.cpp:20:28: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     while (shortest.size() < n) shortest += '_';
            ~~~~~~~~~~~~~~~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...