Submission #395017

#TimeUsernameProblemLanguageResultExecution timeMemory
395017idk321Paint By Numbers (IOI16_paint)C++11
32 / 100
1 ms296 KiB
#include "paint.h"

#include <cstdlib>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

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

    string res = s;

    if (s.size() == 1)
    {
        if (s != ".") return s;
        return "X";
    }

    vector<int> type;
    type.push_back(0);
    for (int i = 0;  i< c.size(); i++)
    {
        for (int j = 0; j < c[i]; j++)
        {
            if (j == c[i] - 1) type.push_back(2);
            else if (j == 0) type.push_back(3);
            else type.push_back(1);
        }
        type.push_back(0);
    }

    int n = s.size();
    vector<vector<bool>> right(n, vector<bool>(type.size()));
    if (s[0] == 'X')
    {
        right[0][1] = true;
    } else if (s[0] == '_')
    {
        right[0][0] = true;
    } else
    {
        right[0][0] = true;
        right[0][1] = true;
    }




    for (int i = 1; i < n; i++)
    {
        for (int j = 0; j < right[i - 1].size(); j++)
        {
            if (right[i - 1][j])
            {
                if (type[j] == 0)
                {
                    if (s[i] == 'X')
                    {
                        if (j + 1 != type.size()) right[i][j + 1] = true;
                    } else if (s[i] == '_')
                    {
                        right[i][j] = true;
                    } else
                    {
                        if (j + 1 != type.size()) right[i][j + 1] = true;
                        right[i][j] = true;
                    }
                } else if (type[j] == 2)
                {
                    if (s[i] == 'X')
                    {

                    } else if (s[i] == '_')
                    {
                        right[i][j + 1] = true;
                    } else
                    {

                        right[i][j + 1] = true;
                    }
                } else
                {
                    if (s[i] == 'X')
                    {
                        right[i][j + 1] = true;
                    } else if (s[i] == '_')
                    {

                    } else
                    {

                        right[i][j + 1] = true;
                    }
                }
            }
        }
    }

    vector<vector<bool>> left(n, vector<bool>(type.size()));
    if (s[n - 1] == 'X')
    {
        left[n - 1][type.size() - 2] = true;
    } else if (s[0] == '_')
    {
        left[n - 1][type.size() - 1] = true;
    } else
    {
        left[n - 1][type.size() - 1] = true;
        left[n - 1][type.size() - 2] = true;
    }



    for (int i = n - 2; i >= 0; i--)
    {
        for (int j = 0; j < right[i + 1].size(); j++)
        {
            if (left[i + 1][j])
            {
                if (type[j] == 0)
                {
                    if (s[i] == 'X')
                    {
                        if (j - 1 >= 0) left[i][j - 1] = true;
                    } else if (s[i] == '_')
                    {
                        left[i][j] = true;
                    } else
                    {
                        if (j - 1 >= 0) left[i][j - 1] = true;
                        left[i][j] = true;
                    }
                } else if (type[j] == 3)
                {
                    if (s[i] == 'X')
                    {

                    } else if (s[i] == '_')
                    {
                        left[i][j - 1] = true;
                    } else
                    {

                        left[i][j - 1] = true;
                    }
                } else
                {
                    if (s[i] == 'X')
                    {
                        left[i][j - 1] = true;
                    } else if (s[i] == '_')
                    {

                    } else
                    {

                        left[i][j - 1] = true;
                    }
                }
            }
        }
    }






    vector<bool> poss1(n);

    vector<bool> poss2(n);
    for (int i = 0; i < n; i++)
    {

        for (int j = 0; j < type.size(); j++)
        {
            if (left[i][j] && right[i][j])
            {
                if (type[j] == 0) poss1[i] = true;
                else poss2[i] = true;
            }
        }
    }

    for (int i = 0; i < n; i++)
    {
        if (poss2[i] && poss1[i])
        {
            res[i] = '?';
        } else if (poss2[i]) res[i] = 'X';
        else res[i] = '_';
    }

    return res;
}

/*
.
1 1
*/

Compilation message (stderr)

paint.cpp: In function 'std::string solve_puzzle(std::string, std::vector<int>)':
paint.cpp:20:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |     for (int i = 0;  i< c.size(); i++)
      |                      ~^~~~~~~~~~
paint.cpp:50:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<bool>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |         for (int j = 0; j < right[i - 1].size(); j++)
      |                         ~~^~~~~~~~~~~~~~~~~~~~~
paint.cpp:58:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |                         if (j + 1 != type.size()) right[i][j + 1] = true;
      |                             ~~~~~~^~~~~~~~~~~~~~
paint.cpp:64:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |                         if (j + 1 != type.size()) right[i][j + 1] = true;
      |                             ~~~~~~^~~~~~~~~~~~~~
paint.cpp:115:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<bool>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  115 |         for (int j = 0; j < right[i + 1].size(); j++)
      |                         ~~^~~~~~~~~~~~~~~~~~~~~
paint.cpp:174:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  174 |         for (int j = 0; j < type.size(); j++)
      |                         ~~^~~~~~~~~~~~~
#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...