#include <cstdio>
#include <iostream>
#include <cstring>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
const int maxn = 100005;
vector<int> d[maxn];
int n, m, k, vis[2][maxn], dp[2][maxn], ok[maxn];
struct node
{
int l, r;
} s[maxn];
bool cmp(node a, node b)
{
return a.l < b.l;
}
int minimumInstructions(int N, int M, int K, vector<int> C, vector<int> A, vector<vector<int>> B)
{
n = N;
m = M;
k = K;
for (int i = 1; i <= n; i++)
C[i - 1]++;
for (int i = 1; i <= m; i++)
{
for (int j = 0; j < A[i - 1]; j++)
B[i - 1][j]++;
}
for (int i = 1; i < maxn; i++)
d[i].push_back(0);
for (int i = 1; i <= m; i++)
{
for (int j = 0; j < A[i - 1]; j++)
d[B[i - 1][j]][0]++, d[B[i - 1][j]].push_back(i);
}
for (int i = n; i >= 1; i--)
{
for (int j = 1; j <= d[C[i - 1]][0]; j++)
{
if (vis[(i + 1) & 1][d[C[i - 1]][j] % m + 1] == i + 1)
dp[i & 1][d[C[i - 1]][j]] = dp[(i + 1) & 1][d[C[i - 1]][j] % m + 1] + 1;
else
dp[i & 1][d[C[i - 1]][j]] = 1;
vis[i & 1][d[C[i - 1]][j]] = i;
if (dp[i & 1][d[C[i - 1]][j]] >= m)
ok[i] = 1;
}
}
if (!ok[1] || !ok[n - m + 1])
return -1;
else if (n == m)
return 1;
int l = 1, r = m, ans = 1;
for (int i = 1; i <= n; i++)
{
while (i < r)
if (ok[++i])
l = i;
if (l == r - m)
return -1;
ans++, r = l + m;
if (r == n + 1)
return ans;
}
return -1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
6492 KB |
Output is correct |
2 |
Incorrect |
5 ms |
8280 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
6492 KB |
Output is correct |
2 |
Incorrect |
5 ms |
8280 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
6492 KB |
Output is correct |
2 |
Incorrect |
5 ms |
8280 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
6492 KB |
Output is correct |
2 |
Incorrect |
5 ms |
8280 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
6492 KB |
Output is correct |
2 |
Incorrect |
5 ms |
8280 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |