제출 #1190499

#제출 시각아이디문제언어결과실행 시간메모리
1190499JelalTkmPaint By Numbers (IOI16_paint)C++17
32 / 100
0 ms328 KiB
#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

using namespace std;

// #define int long long int

const int N = 2e5 + 10;
const int md = 1e9 + 7;
const int INF = 1e9;

string solve_puzzle(string s, vector<int> c) {
  int n = (int) s.size(), k = (int) c.size();
  vector<vector<int>> dp(n, vector<int> (k + 1));
  vector<vector<bool>> visited(n, vector<bool> (k + 1));
  queue<pair<int, int>> q;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < k; j++) {
      if (j == 0) {
        if ((i + 1) >= c[j]) dp[i][j] = 1;
      } else {
        if ((i + 1) >= c[j]) {
          for (int l = i - c[j] - 1; l >= 0; l--) {
            dp[i][j] += dp[l][j - 1];
          }
        }
      }
      if (j == (k - 1) && dp[i][j]) {
        q.push({i, j});
        visited[i][j] = 1;
        ans += dp[i][j];
      }
    }
  }

  vector<int> mn(k, INF), mx(k, -INF);
  while (!q.empty()) {
    auto [ind, ra] = q.front();
    mn[ra] = min(mn[ra], ind);
    mx[ra] = max(mx[ra], ind);
    q.pop();
    if (ra == 0) continue;
    for (int i = ind - c[ra] - 1; i >= 0; i--) {
      if (dp[i][ra - 1] != 0 && !visited[i][ra - 1]) {
        q.push({i, ra - 1});
        visited[i][ra - 1] = 1;
      }
    }
  }

  string an = "";
  for (int i = 0; i < n; i++)
    an += "_";

  for (int i = 0; i < k; i++) {
    for (int j = mx[i] - c[i] + 1; j <= mn[i]; j++)
      an[j] = 'X';
    for (int j = mn[i] - c[i] + 1; j <= mx[i]; j++) {
      if (an[j] == '_') an[j] = '?';
    }
  }

  return an;
}

// int32_t main(int32_t argc, char *argv[]) {
//   ios::sync_with_stdio(false);
//   cin.tie(nullptr);

//   int T = 1;
//   // cin >> T;
//   while (T--) {
//     string s;
//     cin >> s;
//     int n = (int) s.size();
//     int k;
//     cin >> k;
//     vector<int> c(k);
//     for (int i = 0; i < k; i++)
//       cin >> c[i];

//     vector<vector<int>> dp(n, vector<int> (k + 1));
//     vector<vector<bool>> visited(n, vector<bool> (k + 1));
//     queue<pair<int, int>> q;
//     int ans = 0;
//     for (int i = 0; i < n; i++) {
//       for (int j = 0; j < k; j++) {
//         if (j == 0) {
//           if ((i + 1) >= c[j]) dp[i][j] = 1;
//         } else {
//           if ((i + 1) >= c[j]) {
//             for (int l = i - c[j] - 1; l >= 0; l--) {
//               dp[i][j] += dp[l][j - 1];
//             }
//           }
//         }
//         if (j == (k - 1) && dp[i][j] != 0) {
//           q.push({i, j});
//           visited[i][j] = 1;
//           ans += dp[i][j];
//         }
//       }
//     }

//     vector<int> mn(k, INF), mx(k, -INF);
//     while (!q.empty()) {
//       auto [ind, ra] = q.front();
//       mn[ra] = min(mn[ra], ind);
//       mx[ra] = max(mx[ra], ind);
//       q.pop();
//       if (ra == 0) continue;
//       for (int i = ind - c[ra] - 1; i >= 0; i--) {
//         if (dp[i][ra - 1] != 0 && !visited[i][ra - 1]) {
//           q.push({i, ra - 1});
//           visited[i][ra - 1] = 1;
//         }
//       }
//     }

//     string an = "";
//     for (int i = 0; i < n; i++)
//       an += "_";

//     for (int i = 0; i < k; i++) {
//       for (int j = mx[i] - c[i] + 1; j <= mn[i]; j++)
//         an[j] = 'X';
//       for (int j = mn[i] - c[i] + 1; j <= mx[i]; j++) {
//         if (an[j] == '_') an[j] = '?';
//       }
//     }

//     cout << an << '\n';
//   }

//   return 0;
// }

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

paint.h:1:9: warning: #pragma once in main file
    1 | #pragma once
      |         ^~~~
paint_c.h:1:9: warning: #pragma once in main file
    1 | #pragma once
      |         ^~~~
#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...