Submission #553383

# Submission time Handle Problem Language Result Execution time Memory
553383 2022-04-25T16:34:44 Z RaresFelix JOIRIS (JOI16_joiris) C++17
0 / 100
1 ms 468 KB
#include <bits/stdc++.h>

using namespace std;

int main() {
    cin.tie(0)->sync_with_stdio(0);
    int n, k;
    cin >> n >> k;
    vector<int> V(n + 1), R(k);
    for(int i = 1; i <= n; ++i) cin >> V[i], R[(i - 1) % k] = (R[(i - 1) % k] + V[i]) % k;
    bool ok = true;
    for(int i = 0; i < n % k - 1; ++i)
        ok &= R[i] == R[i + 1];
    for(int i = n % k; i < k - 1; ++i)
        ok &= R[i] == R[i + 1];
    if(!ok) {
        cout << "-1\n";
        return 0;
    }
    vector<int> Sol;
    for(int i = 2; i <= n; ++i)
        while(V[i] < V[i-1]) V[i] += k, Sol.push_back(i);
    int nrlin = 0;
    vector<int> S(n + 2);
    for(int i = k; i < n; ++i) {
        for(int rep = V[i + 1] - V[i]; rep --> 0;)
            for(int j = i; j >= k; j -= k)
                Sol.push_back(-(j - k + 1)), ++S[j - k + 1], --S[j + 1];
        nrlin += V[i + 1] - V[i];
    }
    for(int i = 1; i <= n; ++i)
        S[i] += S[i-1], V[i] += S[i];
    for(int i = 1; i <= k; ++i)
        while(V[i] < V[n]) V[i] += k, Sol.push_back(i);
    int mi = numeric_limits<int>::max() / 4;
    for(int i = 1; i <= n; ++i) {
        mi = min(mi, V[i] -= nrlin);
    }
    assert(V[n] == 0);
    for(int i = 1; i <= n; ++i) V[i] -= mi, S[i] = 0;
    for(int rep = 1; rep <= V[1]; ++rep)
        for(int i = n % k + 1; i <= n; i += k)
            Sol.push_back(-i), ++S[i], --S[i + k];
    for(int i = 1; i <= n; ++i) S[i] += S[i-1], V[i] += S[i];
    cout << Sol.size() << "\n";
    for(auto it : Sol)
        cout << (it > 0 ? "1 " : "2 ") << abs(it) << "\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 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 Runtime error 1 ms 468 KB Execution killed with signal 6
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 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 Runtime error 1 ms 468 KB Execution killed with signal 6
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 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 Runtime error 1 ms 468 KB Execution killed with signal 6
5 Halted 0 ms 0 KB -