답안 #57129

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
57129 2018-07-14T06:09:32 Z 강태규(#1651) JOIRIS (JOI16_joiris) C++11
0 / 100
3 ms 572 KB
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdlib>

using namespace std;
typedef long long llong;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<llong, llong> pll;

void fail() {
    printf("-1\n");
    exit(0);
}

vector<pii> ans;

int n, k;
int a[50];
int mod[50];
int main() {
    scanf("%d%d", &n, &k);
    for (int i = 0; i < n; ++i) {
        scanf("%d", a + i);
        mod[i % k] += a[i];
    }
    for (int i = 0; i < k; ++i) mod[i] %= k;
    for (int i = 1; i < n % k; ++i) if (mod[0] != mod[i]) fail();
    for (int i = n % k; i < n; ++i) if (mod[i] != mod[n - 1]) fail(); 
    
    for (int i = 1; i < n; ++i) {
        while (a[i - 1] > a[i]) {
            ans.emplace_back(1, i);
            a[i] += k;
        }
    }
    
    for (int i = k; i < n; ++i) {
        int b = a[i] - a[i - 1];
        for (int j = 0; j < i - k; ++j) {
            while (a[j] < a[i]) {
                ans.emplace_back(1, j);
                a[j] += k;
            }
        }
        for (int j = 0; j < b; ++j) {
            ans.emplace_back(2, i - k);
        }
        for (int j = 0; j < i - k; ++j) {
            a[j] -= b;
        }
        for (int j = i; j < n; ++j) {
            a[j] -= b;
        }
    }
    
    int mx = a[0];
    for (int i = 1; i < k; ++i) mx = max(mx, a[i]);
    for (int i = 0; i < k; ++i) {
        while (a[i] < mx) {
            ans.emplace_back(1, i);
            a[i] += k;
        }
    }
    
    int r = k < n ? a[k] % k : 0;
    while (a[0] % k != r) {
        ans.emplace_back(2, 0);
        ++a[0];
    }
    
    for (int i = 1; i < k; ++i) a[i] = a[0];
    mx = a[0];
    for (int i = 1; i < n; ++i) mx = max(mx, a[i]);
    for (int i = 0; i < n; ++i) {
        while (a[i] < mx) {
            ans.emplace_back(1, i);
            a[i] += k;
        }
    }
    
    printf("%d\n", (int)ans.size());
    for (pii i : ans) {
        printf("%d %d\n", i.first, i.second + 1);
    }
	return 0;
}

Compilation message

joiris.cpp: In function 'int main()':
joiris.cpp:32:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &k);
     ~~~~~^~~~~~~~~~~~~~~~
joiris.cpp:34:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", a + i);
         ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 248 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 2 ms 392 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 3 ms 468 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 3 ms 564 KB Output is correct
8 Correct 2 ms 564 KB Output is correct
9 Correct 2 ms 572 KB Output is correct
10 Correct 2 ms 572 KB Output is correct
11 Incorrect 2 ms 572 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 572 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 248 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 2 ms 392 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 3 ms 468 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 3 ms 564 KB Output is correct
8 Correct 2 ms 564 KB Output is correct
9 Correct 2 ms 572 KB Output is correct
10 Correct 2 ms 572 KB Output is correct
11 Incorrect 2 ms 572 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 248 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 2 ms 392 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 3 ms 468 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 3 ms 564 KB Output is correct
8 Correct 2 ms 564 KB Output is correct
9 Correct 2 ms 572 KB Output is correct
10 Correct 2 ms 572 KB Output is correct
11 Incorrect 2 ms 572 KB Output isn't correct
12 Halted 0 ms 0 KB -