Submission #1037401

#TimeUsernameProblemLanguageResultExecution timeMemory
1037401baldwinhuang1Paint By Numbers (IOI16_paint)C++14
59 / 100
1 ms448 KiB
#include "paint.h" #include <cstdlib> #include <bits/stdc++.h> using namespace std; string solve_puzzle(string s, vector<int> c) { vector<int> start(c.size(), 0); for (int i = 0; i < c.size(); i++) { for (int j = start[i]; j < (s.size() - c[i]); j++) { bool state = true; for (int k = j; k < (j + c[i]); k++) { if (s[k] != '.') { state = false; } } if (state == true) { start[i] = j; if (i != (c.size() - 1)) { start[i + 1] = j + 1 + c[i]; } break; } } } vector<int> end(c.size(), s.size() - 1); for (int i = (c.size() - 1); i >= 0; i--) { for (int j = end[i]; j >= c[i]; j--) { bool state = true; for (int k = j; k > (j - c[i]); k--) { if (s[k] != '.') { state = false; } } if (state == true) { end[i] = j; if (i != (0)) { end[i - 1] = j - 1 - c[i]; } break; } } } // for (auto &i: start) { // cout << i << ' '; // } // cout << '\n'; // for (auto &i: end) { // cout << i << ' '; // } // cout << '\n'; string ans = s; string occ = s; for (int i = 0; i < c.size(); i++) { for (int j = start[i]; j < (end[i] - c[i] + 2); j++) { bool state = true; for (int k = j; k < (j + c[i]); k++) { if (s[k] != '.') { state = false; } } if (state == true) { for (int k = j; k < (j + c[i]); k++) { occ[k] = 'Y'; } } } } for (int i = 0; i < c.size(); i++) { string a = s; string b = s; for (int j = start[i]; j < (end[i] - c[i] + 2); j++) { bool state = true; for (int k = j; k < (j + c[i]); k++) { if (s[k] != '.') { state = false; } } if (state == true) { for (int k = j; k < (j + c[i]); k++) { a[k] = 'X'; } break; } } for (int j = end[i]; j > (start[i] + c[i] - 2); j--) { bool state = true; for (int k = j; k > (j - c[i]); k--) { if (s[k] != '.') { state = false; } } if (state == true) { for (int k = j; k > (j - c[i]); k--) { b[k] = 'X'; } break; } } for (int j = start[i]; j <= end[i]; j++) { if (a[j] == 'X' && b[j] == 'X') { ans[j] = 'X'; } else if (a[j] == 'X' || b[j] == 'X') { ans[j] = '?'; } else if (a[j] == '.' && b[j] == '.') { ans[j] = '?'; } } // cout << a << '\n' << b << '\n'; } for (int i = 0; i < ans.size(); i++) { ans[i] = (occ[i] == '.') ? '_' : ans[i]; } return ans; }

Compilation message (stderr)

paint.cpp: In function 'std::string solve_puzzle(std::string, std::vector<int>)':
paint.cpp:11:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 |     for (int i = 0; i < c.size(); i++) {
      |                     ~~^~~~~~~~~~
paint.cpp:12:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |         for (int j = start[i]; j < (s.size() - c[i]); j++) {
      |                                ~~^~~~~~~~~~~~~~~~~~~
paint.cpp:21:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |                 if (i != (c.size() - 1)) {
      |                     ~~^~~~~~~~~~~~~~~~~
paint.cpp:62:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |     for (int i = 0; i < c.size(); i++) {
      |                     ~~^~~~~~~~~~
paint.cpp:78:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   78 |     for (int i = 0; i < c.size(); i++) {
      |                     ~~^~~~~~~~~~
paint.cpp:123:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  123 |     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...