#include <bits/stdc++.h>
using namespace std;
void chmin(int& a, int b){ if(a > b) a = b; }
void chmax(int& a, int b){ if(a < b) a = b; }
int minimumInstructions(int N, int M, int K, vector<int> C, vector<int> A, vector<vector<int>> B){
vector range(M, pair{-1, -1});
vector next(N, 0);
vector trB(K, vector<int>{});
for(int i = 0; i < M; i++) for(int c : B[i]) trB[c].push_back(i);
for(int i = N; i--; ){
const int c = C[i];
for(int b : trB[c]){
int x = (b - i) % M;
if(x < 0) x += M;
auto& [l, r] = range[x];
if(l != i + 1) r = i + 1;
l = i;
if(r - l >= M) chmax(next[i], r);
}
}
for(int i = 0; i < N - 1; i++) chmax(next[i + 1], next[i]);
for(int i = 0; i < N; i++) chmin(next[i], i + M);
int ans = 0, at = 0;
while(at < N){
if(next[at] == 0) return -1;
at = next[at];
ans++;
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Execution timed out |
1541 ms |
256 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Execution timed out |
1541 ms |
256 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Execution timed out |
1541 ms |
256 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Execution timed out |
1541 ms |
256 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Execution timed out |
1541 ms |
256 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |