답안 #588553

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
588553 2022-07-03T13:51:56 Z MilosMilutinovic 벽 칠하기 (APIO20_paint) C++14
51 / 100
1500 ms 13636 KB
/**
 *    author:  wxhtzdy
 *    created: 03.07.2022 14:53:44
**/
#include <bits/stdc++.h>

using namespace std;

string to_string(string s) {
  return '"' + s + '"';
}
string to_string(const char* s) {
  return to_string((string) s);
}
string to_string(bool b) {
  return (b ? "true" : "false");
}
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

const int inf = (int) 1e6;

template <typename T>
class fenwick {
  public:
  vector<T> fenw;
  int n;
  fenwick(int _n) : n(_n) {
    fenw.resize(n);
  }
  void modify(int x, T v) {
    while (x < n) {
      fenw[x] += v;
      x |= (x + 1);
    }
  }
  T get(int x) {
    T v{};
    while (x >= 0) {
      v += fenw[x];
      x = (x & (x + 1)) - 1;
    }
    return v;
  }
};
struct node {
  int a = inf; // don't forget to set default value
  inline void operator += (node &other) {
    a = min(a, other.a);
  }
};

int minimumInstructions(int n, int m, int k, vector<int> c, vector<int> a, vector<vector<int>> b) {
  vector<vector<int>> ids(k);
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < a[i]; j++) {
      ids[b[i][j]].push_back(i);     
    }
  }                     
  vector<int> len(m);
  vector<bool> is(n);
  for (int i = 0; i < n; i++) {
    vector<int> vec;
    for (int j : ids[c[i]]) {
      vec.push_back(len[(j - 1 + m) % m] + 1);
    }
    if (i > 0) {
      for (int j : ids[c[i - 1]]) {
        len[j] = 0;
      }
    }
    for (int j = 0; j < (int) vec.size(); j++) {
      len[ids[c[i]][j]] = vec[j];
    }
    if (!vec.empty()) {
      is[i] = (*max_element(vec.begin(), vec.end()) >= m);
    }
  }                                 
  vector<int> dp(n, inf);
  fenwick<node> fenw(n);
  for (int i = m - 1; i < n; i++) {
    if (is[i]) {
      if (i == m - 1) {
        dp[i] = 1;
      } else {
        for (int j = i - m + 1; j <= i; j++) {
          dp[i] = min(dp[i], dp[j - 1] + 1);      
        }
      }
    }
    fenw.modify(n - i + 1, {dp[i]});
  }  
  if (dp[n - 1] >= inf) {
    return -1;
  } else {
    return dp[n - 1];
  }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 276 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 300 KB Output is correct
13 Correct 2 ms 2644 KB Output is correct
14 Correct 2 ms 2644 KB Output is correct
15 Correct 2 ms 2600 KB Output is correct
16 Correct 2 ms 2644 KB Output is correct
17 Correct 2 ms 2644 KB Output is correct
18 Correct 2 ms 2644 KB Output is correct
19 Correct 2 ms 2644 KB Output is correct
20 Correct 2 ms 2644 KB Output is correct
21 Correct 2 ms 2644 KB Output is correct
22 Correct 21 ms 7140 KB Output is correct
23 Correct 18 ms 7076 KB Output is correct
24 Correct 26 ms 7116 KB Output is correct
25 Correct 3 ms 596 KB Output is correct
26 Correct 3 ms 540 KB Output is correct
27 Correct 3 ms 596 KB Output is correct
28 Correct 3 ms 564 KB Output is correct
29 Correct 3 ms 596 KB Output is correct
30 Correct 3 ms 568 KB Output is correct
31 Correct 47 ms 4052 KB Output is correct
32 Correct 48 ms 4148 KB Output is correct
33 Correct 51 ms 4128 KB Output is correct
34 Correct 52 ms 4120 KB Output is correct
35 Correct 49 ms 4116 KB Output is correct
36 Correct 48 ms 4052 KB Output is correct
37 Correct 22 ms 7676 KB Output is correct
38 Correct 23 ms 7728 KB Output is correct
39 Correct 26 ms 7652 KB Output is correct
40 Correct 12 ms 1848 KB Output is correct
41 Correct 10 ms 1208 KB Output is correct
42 Correct 18 ms 2004 KB Output is correct
43 Correct 9 ms 1464 KB Output is correct
44 Correct 12 ms 1292 KB Output is correct
45 Correct 14 ms 2004 KB Output is correct
46 Execution timed out 1577 ms 13636 KB Time limit exceeded
47 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 276 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 300 KB Output is correct
13 Correct 2 ms 2644 KB Output is correct
14 Correct 2 ms 2644 KB Output is correct
15 Correct 2 ms 2600 KB Output is correct
16 Correct 2 ms 2644 KB Output is correct
17 Correct 2 ms 2644 KB Output is correct
18 Correct 2 ms 2644 KB Output is correct
19 Correct 2 ms 2644 KB Output is correct
20 Correct 2 ms 2644 KB Output is correct
21 Correct 2 ms 2644 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 300 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 1 ms 300 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 296 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 2 ms 2260 KB Output is correct
34 Correct 1 ms 1840 KB Output is correct
35 Correct 2 ms 1620 KB Output is correct
36 Correct 2 ms 2644 KB Output is correct
37 Correct 2 ms 2132 KB Output is correct
38 Correct 2 ms 2388 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 2 ms 2132 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 2 ms 2516 KB Output is correct
43 Correct 2 ms 2388 KB Output is correct
44 Correct 1 ms 300 KB Output is correct
45 Correct 1 ms 212 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 1 ms 300 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 1 ms 212 KB Output is correct
50 Correct 2 ms 2612 KB Output is correct
51 Correct 2 ms 2608 KB Output is correct
52 Correct 2 ms 2644 KB Output is correct
53 Correct 3 ms 2644 KB Output is correct
54 Correct 2 ms 2644 KB Output is correct
55 Correct 2 ms 2644 KB Output is correct
56 Correct 2 ms 2644 KB Output is correct
57 Correct 1 ms 340 KB Output is correct
58 Correct 2 ms 2616 KB Output is correct
59 Correct 1 ms 300 KB Output is correct
60 Correct 2 ms 2644 KB Output is correct
61 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 300 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 276 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 300 KB Output is correct
15 Correct 2 ms 2644 KB Output is correct
16 Correct 2 ms 2644 KB Output is correct
17 Correct 2 ms 2600 KB Output is correct
18 Correct 2 ms 2644 KB Output is correct
19 Correct 2 ms 2644 KB Output is correct
20 Correct 2 ms 2644 KB Output is correct
21 Correct 2 ms 2644 KB Output is correct
22 Correct 2 ms 2644 KB Output is correct
23 Correct 2 ms 2644 KB Output is correct
24 Correct 21 ms 7140 KB Output is correct
25 Correct 18 ms 7076 KB Output is correct
26 Correct 26 ms 7116 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 1 ms 300 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 296 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 2 ms 2260 KB Output is correct
37 Correct 1 ms 1840 KB Output is correct
38 Correct 2 ms 1620 KB Output is correct
39 Correct 2 ms 2644 KB Output is correct
40 Correct 2 ms 2132 KB Output is correct
41 Correct 2 ms 2388 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 2 ms 2132 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 2 ms 2516 KB Output is correct
46 Correct 2 ms 2388 KB Output is correct
47 Correct 1 ms 300 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 1 ms 212 KB Output is correct
50 Correct 1 ms 300 KB Output is correct
51 Correct 1 ms 212 KB Output is correct
52 Correct 1 ms 212 KB Output is correct
53 Correct 2 ms 2612 KB Output is correct
54 Correct 2 ms 2608 KB Output is correct
55 Correct 2 ms 2644 KB Output is correct
56 Correct 3 ms 2644 KB Output is correct
57 Correct 2 ms 2644 KB Output is correct
58 Correct 2 ms 2644 KB Output is correct
59 Correct 2 ms 2644 KB Output is correct
60 Correct 1 ms 340 KB Output is correct
61 Correct 2 ms 2616 KB Output is correct
62 Correct 1 ms 300 KB Output is correct
63 Correct 2 ms 2644 KB Output is correct
64 Correct 1 ms 340 KB Output is correct
65 Correct 1 ms 212 KB Output is correct
66 Correct 1 ms 212 KB Output is correct
67 Correct 2 ms 212 KB Output is correct
68 Correct 1 ms 212 KB Output is correct
69 Correct 1 ms 212 KB Output is correct
70 Correct 3 ms 2516 KB Output is correct
71 Correct 3 ms 2132 KB Output is correct
72 Correct 3 ms 1876 KB Output is correct
73 Correct 2 ms 2004 KB Output is correct
74 Correct 4 ms 2388 KB Output is correct
75 Correct 3 ms 2772 KB Output is correct
76 Correct 18 ms 5152 KB Output is correct
77 Correct 17 ms 6084 KB Output is correct
78 Correct 22 ms 6788 KB Output is correct
79 Correct 3 ms 300 KB Output is correct
80 Correct 2 ms 212 KB Output is correct
81 Correct 3 ms 340 KB Output is correct
82 Correct 2 ms 212 KB Output is correct
83 Correct 3 ms 340 KB Output is correct
84 Correct 4 ms 2872 KB Output is correct
85 Correct 3 ms 2952 KB Output is correct
86 Correct 4 ms 2900 KB Output is correct
87 Correct 4 ms 2900 KB Output is correct
88 Correct 5 ms 2900 KB Output is correct
89 Correct 4 ms 2900 KB Output is correct
90 Correct 29 ms 7252 KB Output is correct
91 Correct 29 ms 7268 KB Output is correct
92 Correct 29 ms 7228 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 300 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 276 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 300 KB Output is correct
15 Correct 2 ms 2644 KB Output is correct
16 Correct 2 ms 2644 KB Output is correct
17 Correct 2 ms 2600 KB Output is correct
18 Correct 2 ms 2644 KB Output is correct
19 Correct 2 ms 2644 KB Output is correct
20 Correct 2 ms 2644 KB Output is correct
21 Correct 2 ms 2644 KB Output is correct
22 Correct 2 ms 2644 KB Output is correct
23 Correct 2 ms 2644 KB Output is correct
24 Correct 21 ms 7140 KB Output is correct
25 Correct 18 ms 7076 KB Output is correct
26 Correct 26 ms 7116 KB Output is correct
27 Correct 3 ms 596 KB Output is correct
28 Correct 3 ms 540 KB Output is correct
29 Correct 3 ms 596 KB Output is correct
30 Correct 3 ms 564 KB Output is correct
31 Correct 3 ms 596 KB Output is correct
32 Correct 3 ms 568 KB Output is correct
33 Correct 47 ms 4052 KB Output is correct
34 Correct 48 ms 4148 KB Output is correct
35 Correct 51 ms 4128 KB Output is correct
36 Correct 52 ms 4120 KB Output is correct
37 Correct 49 ms 4116 KB Output is correct
38 Correct 48 ms 4052 KB Output is correct
39 Correct 22 ms 7676 KB Output is correct
40 Correct 23 ms 7728 KB Output is correct
41 Correct 26 ms 7652 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 1 ms 300 KB Output is correct
44 Correct 1 ms 212 KB Output is correct
45 Correct 1 ms 212 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 1 ms 296 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 1 ms 212 KB Output is correct
50 Correct 1 ms 212 KB Output is correct
51 Correct 2 ms 2260 KB Output is correct
52 Correct 1 ms 1840 KB Output is correct
53 Correct 2 ms 1620 KB Output is correct
54 Correct 2 ms 2644 KB Output is correct
55 Correct 2 ms 2132 KB Output is correct
56 Correct 2 ms 2388 KB Output is correct
57 Correct 1 ms 212 KB Output is correct
58 Correct 2 ms 2132 KB Output is correct
59 Correct 1 ms 340 KB Output is correct
60 Correct 2 ms 2516 KB Output is correct
61 Correct 2 ms 2388 KB Output is correct
62 Correct 1 ms 300 KB Output is correct
63 Correct 1 ms 212 KB Output is correct
64 Correct 1 ms 212 KB Output is correct
65 Correct 1 ms 300 KB Output is correct
66 Correct 1 ms 212 KB Output is correct
67 Correct 1 ms 212 KB Output is correct
68 Correct 2 ms 2612 KB Output is correct
69 Correct 2 ms 2608 KB Output is correct
70 Correct 2 ms 2644 KB Output is correct
71 Correct 3 ms 2644 KB Output is correct
72 Correct 2 ms 2644 KB Output is correct
73 Correct 2 ms 2644 KB Output is correct
74 Correct 2 ms 2644 KB Output is correct
75 Correct 1 ms 340 KB Output is correct
76 Correct 2 ms 2616 KB Output is correct
77 Correct 1 ms 300 KB Output is correct
78 Correct 2 ms 2644 KB Output is correct
79 Correct 1 ms 340 KB Output is correct
80 Correct 1 ms 212 KB Output is correct
81 Correct 1 ms 212 KB Output is correct
82 Correct 2 ms 212 KB Output is correct
83 Correct 1 ms 212 KB Output is correct
84 Correct 1 ms 212 KB Output is correct
85 Correct 3 ms 2516 KB Output is correct
86 Correct 3 ms 2132 KB Output is correct
87 Correct 3 ms 1876 KB Output is correct
88 Correct 2 ms 2004 KB Output is correct
89 Correct 4 ms 2388 KB Output is correct
90 Correct 3 ms 2772 KB Output is correct
91 Correct 18 ms 5152 KB Output is correct
92 Correct 17 ms 6084 KB Output is correct
93 Correct 22 ms 6788 KB Output is correct
94 Correct 3 ms 300 KB Output is correct
95 Correct 2 ms 212 KB Output is correct
96 Correct 3 ms 340 KB Output is correct
97 Correct 2 ms 212 KB Output is correct
98 Correct 3 ms 340 KB Output is correct
99 Correct 4 ms 2872 KB Output is correct
100 Correct 3 ms 2952 KB Output is correct
101 Correct 4 ms 2900 KB Output is correct
102 Correct 4 ms 2900 KB Output is correct
103 Correct 5 ms 2900 KB Output is correct
104 Correct 4 ms 2900 KB Output is correct
105 Correct 29 ms 7252 KB Output is correct
106 Correct 29 ms 7268 KB Output is correct
107 Correct 29 ms 7228 KB Output is correct
108 Correct 4 ms 596 KB Output is correct
109 Correct 144 ms 508 KB Output is correct
110 Correct 76 ms 496 KB Output is correct
111 Correct 60 ms 468 KB Output is correct
112 Correct 66 ms 560 KB Output is correct
113 Correct 45 ms 516 KB Output is correct
114 Correct 24 ms 4268 KB Output is correct
115 Correct 13 ms 3876 KB Output is correct
116 Correct 31 ms 4508 KB Output is correct
117 Correct 20 ms 3608 KB Output is correct
118 Correct 15 ms 4192 KB Output is correct
119 Correct 32 ms 4024 KB Output is correct
120 Correct 19 ms 4940 KB Output is correct
121 Correct 26 ms 1340 KB Output is correct
122 Correct 21 ms 5112 KB Output is correct
123 Correct 11 ms 1204 KB Output is correct
124 Correct 25 ms 6168 KB Output is correct
125 Correct 10 ms 1744 KB Output is correct
126 Correct 7 ms 2772 KB Output is correct
127 Correct 11 ms 3540 KB Output is correct
128 Correct 7 ms 3028 KB Output is correct
129 Correct 7 ms 2516 KB Output is correct
130 Correct 3 ms 564 KB Output is correct
131 Correct 207 ms 716 KB Output is correct
132 Correct 138 ms 720 KB Output is correct
133 Correct 111 ms 732 KB Output is correct
134 Correct 104 ms 744 KB Output is correct
135 Correct 84 ms 756 KB Output is correct
136 Correct 61 ms 4960 KB Output is correct
137 Correct 60 ms 5076 KB Output is correct
138 Correct 58 ms 4852 KB Output is correct
139 Correct 69 ms 4972 KB Output is correct
140 Correct 60 ms 4976 KB Output is correct
141 Correct 60 ms 4972 KB Output is correct
142 Correct 58 ms 7844 KB Output is correct
143 Correct 46 ms 2004 KB Output is correct
144 Correct 32 ms 7836 KB Output is correct
145 Correct 65 ms 2004 KB Output is correct
146 Correct 34 ms 7840 KB Output is correct
147 Correct 50 ms 1892 KB Output is correct
148 Correct 10 ms 4320 KB Output is correct
149 Correct 10 ms 4140 KB Output is correct
150 Correct 16 ms 4152 KB Output is correct
151 Correct 10 ms 4120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 300 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 276 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 300 KB Output is correct
15 Correct 2 ms 2644 KB Output is correct
16 Correct 2 ms 2644 KB Output is correct
17 Correct 2 ms 2600 KB Output is correct
18 Correct 2 ms 2644 KB Output is correct
19 Correct 2 ms 2644 KB Output is correct
20 Correct 2 ms 2644 KB Output is correct
21 Correct 2 ms 2644 KB Output is correct
22 Correct 2 ms 2644 KB Output is correct
23 Correct 2 ms 2644 KB Output is correct
24 Correct 21 ms 7140 KB Output is correct
25 Correct 18 ms 7076 KB Output is correct
26 Correct 26 ms 7116 KB Output is correct
27 Correct 3 ms 596 KB Output is correct
28 Correct 3 ms 540 KB Output is correct
29 Correct 3 ms 596 KB Output is correct
30 Correct 3 ms 564 KB Output is correct
31 Correct 3 ms 596 KB Output is correct
32 Correct 3 ms 568 KB Output is correct
33 Correct 47 ms 4052 KB Output is correct
34 Correct 48 ms 4148 KB Output is correct
35 Correct 51 ms 4128 KB Output is correct
36 Correct 52 ms 4120 KB Output is correct
37 Correct 49 ms 4116 KB Output is correct
38 Correct 48 ms 4052 KB Output is correct
39 Correct 22 ms 7676 KB Output is correct
40 Correct 23 ms 7728 KB Output is correct
41 Correct 26 ms 7652 KB Output is correct
42 Correct 12 ms 1848 KB Output is correct
43 Correct 10 ms 1208 KB Output is correct
44 Correct 18 ms 2004 KB Output is correct
45 Correct 9 ms 1464 KB Output is correct
46 Correct 12 ms 1292 KB Output is correct
47 Correct 14 ms 2004 KB Output is correct
48 Execution timed out 1577 ms 13636 KB Time limit exceeded
49 Halted 0 ms 0 KB -