Submission #610966

#TimeUsernameProblemLanguageResultExecution timeMemory
610966strange420Paint By Numbers (IOI16_paint)C++14
32 / 100
1 ms312 KiB
#include "paint.h"
#include <bits/stdc++.h>
#include <cstdlib>

using namespace std;

bool isEmpty(string s) {
    for (char x: s)
        if (x != '.') return false;
    return true;
}

std::string solve_puzzle(std::string s, std::vector<int> c) {
    string ans;
    int n = s.size(), k = c.size();
    for (int i=0; i<n; i++) ans += '?';

    if (k == 1) {
        k = c[0];
        for (int i=0; i<2*k-n; i++) ans[i+n-k] = 'X';

        return ans;
    } else if (isEmpty(s)) {
        int totalSpace = k-1;
        for (int x: c) totalSpace += x;

        int gap = n - totalSpace, pt = 0;
        for (int i=0; i<k; i++) {
            // solve(start: pt, end: pt + gap + c_i (exclusive))
            int tempN = gap + c[i];
            for (int j=0; j<2*c[i]-tempN; j++) {
                ans[pt + j + tempN - c[i]] = 'X';
            }
            
            pt += c[i] + 1; // size + gap
        }

        if (gap == 0)
            for(int i=0; i<ans.size(); i++)
                if (ans[i] != 'X') ans[i] = '_';
    }
    return ans;
}

Compilation message (stderr)

paint.cpp: In function 'std::string solve_puzzle(std::string, std::vector<int>)':
paint.cpp:39:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |             for(int i=0; i<ans.size(); i++)
      |                          ~^~~~~~~~~~~
#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...