# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
57148 | gs13105 | JOIRIS (JOI16_joiris) | C++17 | 4 ms | 1068 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <iterator>
using namespace std;
int arr[60];
int cur[60];
int tmp[60];
int cnt[60];
int main()
{
//freopen("in", "r", stdin);
//freopen("out", "w", stdout);
int n, l, i, j, k;
scanf("%d%d", &n, &l);
for(i = 1; i <= n; i++)
scanf("%d", &arr[i]);
for(i = 0; i < l; i++)
{
for(j = 1; j <= n; j++)
{
cur[j] = arr[j];
tmp[j] = (arr[j] + i) % l;
}
for(j = 1; j <= n - l + 1; j++)
{
cnt[j] = (l - tmp[j]) % l;
for(k = j; k < j + l; k++)
tmp[k] = (tmp[k] + cnt[j]) % l;
}
bool ok = 1;
for(j = 1; j <= n; j++)
{
if(tmp[j])
{
ok = 0;
break;
}
}
if(!ok)
continue;
vector<pair<int, int>> res;
for(j = 1; j <= n - l + 1; j++)
{
for(k = 0; k < cnt[j]; k++)
res.push_back({ 2, j });
int mx = 0;
for(k = j; k < j + l; k++)
mx = max(mx, cur[k]);
int mn = 1e9;
for(k = 1; k <= n; k++)
{
if(j <= k && k < j + l)
cur[k] += cnt[j];
else
{
while(cur[k] < mx + cnt[j])
{
res.push_back({ 1, k });
cur[k] += l;
}
}
mn = min(mn, cur[k]);
}
for(k = 1; k <= n; k++)
cur[k] -= mn;
}
int mx = 0;
for(j = 1; j <= n; j++)
mx = max(mx, cur[j]);
for(j = 1; j <= n; j++)
{
while(cur[j] < mx)
{
res.push_back({ 1, j });
cur[j] += l;
}
}
printf("%d\n", (int)res.size());
for(auto &p : res)
printf("%d %d\n", p.first, p.second);
return 0;
}
printf("-1\n");
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |