답안 #106127

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
106127 2019-04-16T17:14:31 Z cki86201 JOIRIS (JOI16_joiris) C++11
45 / 100
19 ms 384 KB
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_set>
#include <bitset>
#include <time.h>
#include <limits.h>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define Fi first
#define Se second
#define pb push_back
#define szz(x) (int)x.size()
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) x.begin(),x.end()
typedef tuple<int, int, int> t3;

int N, K;
int A[55];
ll X[105050];
int H[55];
ll FULL;

vector <pii> ans;

void erase(int x) {
	int mxh = -1;
	for(int i=1;i<=N;i++) mxh = max(mxh, H[i]);
	for(int i=x;i<mxh;i++) X[i] = X[i+1];
	X[mxh] = 0;
}

void fix_h() {
	for(int i=1;i<=N;i++) {
		while(H[i] > 0 && !(X[H[i]] & 1LL << i)) --H[i];
	}
}

void put(int vert, int x) {
	ans.pb(pii(vert, x));
	if(vert == 2) {
		for(int i=x;i<x+K;i++) A[i] += 1;
		
		int mx = -1;
		for(int i=x;i<x+K;i++) mx = max(mx, H[i]);
		for(int i=x;i<x+K;i++) H[i] = mx + 1;
		X[mx + 1] += 1LL << (x + K);
		X[mx + 1] -= 1LL << x;
		if(X[mx + 1] == FULL) {
			erase(mx + 1);
			fix_h();
		}
	}
	else {
		A[x] += K;
		
		int h = H[x];
		for(int i=h+1;i<=h+K;i++) X[i] |= 1LL << x;
		H[x] += K;
		for(int a=0, i=h+1;a<K;a++) {
			if(X[i] == FULL) {
				erase(i);
				fix_h();
			}
			else ++i;
		}
	}
}

void print() {
	for(int i=1;i<=N;i++) printf("%d", H[i]); puts("");
	int mxh = -1;
	for(int i=1;i<=N;i++) mxh = max(mxh, H[i]);
	for(int i=mxh;i;i--) {
		for(int j=1;j<=N;j++) {
			printf("%c", (X[i] & 1LL << j) ? 'O' : '.');
		} puts("");
	}
}

int main() {
	scanf("%d%d", &N, &K);
	FULL = (1LL << (N + 1)) - 2;
	for(int i=1;i<=N;i++) scanf("%d", A + i);
	for(int i=1;i<=N;i++) {
		H[i] = A[i];
		for(int j=1;j<=A[i];j++) X[j] |= 1LL << i;
	}
	
	int tsum = 0;
	for(int i=1;i<=N;i++) tsum += A[i];
	int tar = -1;
	for(int i=0;i<K;i++) if(N * i % K == tsum % K) {
		tar = i; break;
	}
	if(tar == -1) {
		puts("-1");
		return 0;
	}
	for(int i=1;i+K-1<=N;i++) {
		while(A[i] % K != tar) put(2, i);
	}
	for(int i=N-K+2;i<=N;i++) {
		int delta = (tar - A[i]);
		if(delta % K != 0) {
			puts("-1");
			return 0;
		}
		while(A[i] < tar) put(1, i);
	}
	while(1) {
		int mxh = -1;
		for(int i=1;i<=N;i++) mxh = max(mxh, H[i]);
		if(mxh == 0) break;
		int f = -1;
		for(int i=1;i<=N;i++) if(!(1LL<<i & X[mxh])) {
			if(f == -1 || H[f] > H[i]) f = i;
		}
		put(1, f);
	}
	printf("%d\n", szz(ans));
	for(pii e : ans) printf("%d %d\n", e.Fi, e.Se);
	
	return 0;
}

Compilation message

joiris.cpp: In function 'void print()':
joiris.cpp:85:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
  for(int i=1;i<=N;i++) printf("%d", H[i]); puts("");
  ^~~
joiris.cpp:85:44: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
  for(int i=1;i<=N;i++) printf("%d", H[i]); puts("");
                                            ^~~~
joiris.cpp: In function 'int main()':
joiris.cpp:96:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &N, &K);
  ~~~~~^~~~~~~~~~~~~~~~
joiris.cpp:98:29: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=1;i<=N;i++) scanf("%d", A + i);
                        ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 3 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 252 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 3 ms 256 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 19 ms 256 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 3 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 284 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 3 ms 384 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 2 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 3 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 252 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 3 ms 256 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 19 ms 256 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 3 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 3 ms 384 KB Output is correct
19 Correct 3 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 3 ms 384 KB Output is correct
23 Correct 3 ms 384 KB Output is correct
24 Correct 3 ms 384 KB Output is correct
25 Correct 3 ms 384 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 3 ms 384 KB Output is correct
28 Correct 3 ms 384 KB Output is correct
29 Correct 3 ms 384 KB Output is correct
30 Correct 2 ms 256 KB Output is correct
31 Correct 2 ms 384 KB Output is correct
32 Correct 2 ms 384 KB Output is correct
33 Correct 3 ms 384 KB Output is correct
34 Correct 3 ms 384 KB Output is correct
35 Correct 3 ms 384 KB Output is correct
36 Correct 2 ms 384 KB Output is correct
37 Correct 2 ms 384 KB Output is correct
38 Correct 2 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 3 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 252 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 3 ms 256 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 19 ms 256 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 3 ms 384 KB Output is correct
17 Correct 3 ms 384 KB Output is correct
18 Correct 3 ms 384 KB Output is correct
19 Correct 2 ms 256 KB Output is correct
20 Correct 2 ms 256 KB Output is correct
21 Correct 3 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 3 ms 384 KB Output is correct
24 Correct 2 ms 256 KB Output is correct
25 Correct 2 ms 256 KB Output is correct
26 Correct 2 ms 284 KB Output is correct
27 Correct 2 ms 384 KB Output is correct
28 Correct 2 ms 256 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
30 Correct 3 ms 384 KB Output is correct
31 Correct 2 ms 256 KB Output is correct
32 Correct 2 ms 256 KB Output is correct
33 Correct 2 ms 384 KB Output is correct
34 Correct 3 ms 384 KB Output is correct
35 Correct 3 ms 384 KB Output is correct
36 Correct 2 ms 384 KB Output is correct
37 Correct 2 ms 384 KB Output is correct
38 Correct 3 ms 384 KB Output is correct
39 Correct 3 ms 384 KB Output is correct
40 Correct 3 ms 384 KB Output is correct
41 Correct 3 ms 384 KB Output is correct
42 Correct 2 ms 384 KB Output is correct
43 Correct 3 ms 384 KB Output is correct
44 Correct 3 ms 384 KB Output is correct
45 Correct 3 ms 384 KB Output is correct
46 Correct 2 ms 256 KB Output is correct
47 Correct 2 ms 384 KB Output is correct
48 Correct 2 ms 384 KB Output is correct
49 Correct 3 ms 384 KB Output is correct
50 Correct 3 ms 384 KB Output is correct
51 Correct 3 ms 384 KB Output is correct
52 Correct 2 ms 384 KB Output is correct
53 Correct 2 ms 384 KB Output is correct
54 Correct 2 ms 256 KB Output is correct
55 Correct 2 ms 256 KB Output is correct
56 Correct 2 ms 304 KB Output is correct
57 Correct 2 ms 256 KB Output is correct
58 Correct 2 ms 384 KB Output is correct
59 Correct 2 ms 256 KB Output is correct
60 Correct 2 ms 256 KB Output is correct
61 Correct 2 ms 384 KB Output is correct
62 Correct 2 ms 384 KB Output is correct
63 Correct 2 ms 384 KB Output is correct
64 Incorrect 2 ms 384 KB Output isn't correct
65 Halted 0 ms 0 KB -