제출 #427186

#제출 시각아이디문제언어결과실행 시간메모리
427186MazaalaiPaint By Numbers (IOI16_paint)C++14
59 / 100
6 ms252 KiB
#include "paint.h" #include <bits/stdc++.h> using namespace std; string solve_puzzle(string s, vector<int> c1) { int n = s.size(), k = c1.size(); vector <int> c(k+5, 0); for (int i = 1; i <= k; i++) c[i] = c1[i-1]; string ans = ""; for (int i = 0; i < n+2; i++) { ans += '?'; } for (int i = 1; i <= n; i++) { if (s[i-1] != '.') ans[i] = s[i-1]; } vector <int> pre(k+5, 1), suf(k + 5, n); vector <int> white(1, 0); for (int i = 0; i < n; i++) { if (s[i] == '_') white.push_back(i+1); } white.push_back(n+1); for (int i = 1; i < white.size(); i++) { int len = white[i] - white[i-1] - 1; // cout << i << ": " << len << '\n'; if (len < c[1]) { continue; } pre[1] = white[i-1]+1; break; } for (int i = white.size()-1; i > 0; i--) { int len = white[i] - white[i-1] - 1; if (len < c[k]) continue; suf[k] = white[i]-1; break; } vector <bool> temp(n + 5, 0); for (int i = 2; i <= k; i++) { int st = pre[i-1]+c[i-1]+1, end = st + c[i]-1; int tmp = st; while(1) { auto it = lower_bound(white.begin(), white.end(), st); if (*it <= end) { st = *it+1; end = st + c[i]-1; } else break; } for (int j = tmp; j < st; j++) temp[j] = 1; pre[i] = st; } for (int i = k-1; i >= 1; i--) { int end = suf[i+1] - c[i+1] - 1, st = end - c[i] + 1; int tmp = end; while(1) { auto it = lower_bound(white.begin(), white.end(), st); if (*it <= end) { end = *it-1; st = end - c[i] + 1; } else break; } suf[i] = end; } // for (int i = k - 1; i > 0; i--) { // suf[i] = suf[i+1] - c[i+1] - 1; // } for (int i = 0; i < pre[1]; i++) ans[i] = '_'; for (int i = suf[k]+1; i <= n; i++) ans[i] = '_'; // cout << "here: " << k << '\n'; for (int i = 1; i <= k; i++) { // cout << i << ": " << pre[i] << ' ' << suf[i] << '\n'; int len = suf[i] - pre[i] + 1; if (len >= c[i] * 2) continue; if (len == c[i]) for (int j = pre[i]; j <= suf[i]; j++) ans[j] = 'X'; int len1 = c[i] * 2 - len; for (int j = 0; j < len1; j++) { ans[j + c[i] - len1 + pre[i]] = 'X'; } } for (int i = 2; i <= k; i++) { int a = pre[i-1], b = suf[i-1]; int a1 = pre[i], b1 = suf[i]; for (int j = b+1; j < a1; j++) ans[j] = '_'; } for (int i = 1; i < white.size() && white.size() != 2; i++) { int st = white[i-1]+1, end = white[i]-1; bool x = 0; for (int j = 1; j <= k; j++) { int a = pre[j], b = suf[j], len1 = c[j]; int a1 = max(st, pre[j]), b1 = min(b, end), len = b1 - a1 + 1; // cout << len << ' ' << len1 << '\n'; if (len >= len1) { x = 1; break; } } if (!x) { for (int j = st; j <= end; j++) ans[j] = '_'; } } ans = ans.substr(1, n); return ans; }

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

paint.cpp: In function 'std::string solve_puzzle(std::string, std::vector<int>)':
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 |     for (int i = 1; i < white.size(); i++) {
      |                     ~~^~~~~~~~~~~~~~
paint.cpp:52:13: warning: unused variable 'tmp' [-Wunused-variable]
   52 |         int tmp = end;
      |             ^~~
paint.cpp:81:13: warning: unused variable 'a' [-Wunused-variable]
   81 |         int a = pre[i-1], b = suf[i-1];
      |             ^
paint.cpp:82:26: warning: unused variable 'b1' [-Wunused-variable]
   82 |         int a1 = pre[i], b1 = suf[i];
      |                          ^~
paint.cpp:85:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   85 |     for (int i = 1; i < white.size() && white.size() != 2; i++) {
      |                     ~~^~~~~~~~~~~~~~
paint.cpp:89:17: warning: unused variable 'a' [-Wunused-variable]
   89 |             int a = pre[j], b = suf[j], len1 = c[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...