제출 #239824

#제출 시각아이디문제언어결과실행 시간메모리
239824nicolaalexandraPaint By Numbers (IOI16_paint)C++14
59 / 100
6 ms384 KiB
#include <bits/stdc++.h>
#include "paint.h"
#define DIM 100010
using namespace std;

int sp[DIM],Left[DIM],Right[DIM];

int get_sum (int x, int y){
    int sol = sp[y];
    if (x)
        sol -= sp[x-1];
    return sol;
}

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

    int n = s.length(), i, j;

    for (i=0;i<n;i++){
        sp[i] = i ? sp[i-1] : 0;
        if (s[i] == '_')
            sp[i]++;
    }

    /// left[i] - cea mai din stanga pozitie pe care poate sa inceapa blocul i

    int pos = 0;
    for (i=0;i<c.size();i++){
        int lg = c[i];
        while (get_sum(pos, pos+lg-1))
            pos++;

        Left[i] = pos;

        pos += lg + 1;
    }

    pos = n-1;
    for (i=c.size()-1;i>=0;i--){
        int lg = c[i];
        while (get_sum(pos-lg+1,pos))
            pos--;

        Right[i] = pos - lg + 1;

        pos -= lg + 1;
    }

    for (i=0;i<c.size();i++){
        int lg = c[i];
        for (j=Right[i];j<=Left[i]+lg-1;j++)
            s[j] = 'X';
        for (j=Left[i];j<Right[i];j++){
            if (s[j] == '.')
                s[j] = '?';
        }
        for (j=Left[i]+lg;j<=Right[i]+lg-1;j++){
            if (s[j] == '.')
                s[j] = '?';
        }
    }

    for (i=0;i<n;i++)
        if (s[i] == '.')
            s[i] = '_';

    return s;
}

컴파일 시 표준 에러 (stderr) 메시지

paint.cpp: In function 'std::__cxx11::string solve_puzzle(std::__cxx11::string, std::vector<int>)':
paint.cpp:28:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (i=0;i<c.size();i++){
              ~^~~~~~~~~
paint.cpp:49:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (i=0;i<c.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...