답안 #65161

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
65161 2018-08-06T22:11:37 Z reality JOIRIS (JOI16_joiris) C++17
30 / 100
1000 ms 66524 KB
#include "bits/stdc++.h"
using namespace std;
#define fi first
#define se second
#define ll long long
#define dbg(v) cerr<<#v<<" = "<<v<<'\n'
#define vi vector<int>
#define vl vector <ll>
#define pii pair<int,int>
#define mp make_pair
#define db long double
#define pb push_back
#define all(s) s.begin(),s.end()
template < class T > ostream& operator<<(ostream& stream, const vector<T> v){ stream << "[ "; for (int i=0; i<(int)v.size(); i++) stream << v[i] << " "; stream << "]"; return stream;}
template < class T > T smin(T &a,T b) {if (a > b) a = b;return a;}
template < class T > T smax(T &a,T b) {if (a < b) a = b;return a;}
vector < ll > A;
int MX,n,k;
ll One;
vector < pii > answer;
void G(int sz) {
	while (A.size() <= sz)
		A.pb(0ll);
}
int add1(int index) {
	int ok = 0;
	answer.pb(mp(1,index));
	int lst = -1;
	for (int i = 0;i < A.size();++i)
		if (A[i] & (1ll << index))
			lst = i;
	for (int cs = 0,i = lst + 1;cs < k && i <= lst + k;++cs,++i) {
		G(i);
		A[i] |= 1ll << index;
		if (A[i] == One) {
			A.erase(A.begin() + i);
			ok = 1;
			--i;--lst;
		}
	}
	return ok;
}
int add2(int index) {
	int ok = 0;
	answer.pb(mp(2,index));
	int lst = -1;
	for (int i = index;i < index + k;++i)
		for (int j = 0;j < A.size() && (A[j] & (1ll << i));++j)
				smax(lst,j);
	G(++lst);
	for (int i = index;i < index + k;++i)
		A[lst] |= 1ll << i;
	if (A[lst] == One)
		A.erase(A.begin() + lst),ok = 1;
	return ok;
}
int main(void) {
    cin>>n>>k;
    One = (1ll << n) - 1;
    vi s(n);
    for (auto & it : s)
    	cin>>it;
    vi sum(k,0);
    for (int i = 0;i < n;++i)
    	(sum[i % k] += s[i]) %= k;
    int ok = 0;
    for (int i = 0;i + 1 < (n % k);++i)
    	if (sum[i] != sum[i + 1])
    		return puts("-1") * 0;
    for (int i = (n % k);i + 1 < k;++i)
    	if (sum[i] != sum[i + 1])
    		return puts("-1") * 0;
    for (int i = 0;i < n;++i) {
    	G(s[i]);
    	for (int j = 0;j < s[i];++j)
    		A[j] |= 1ll << i;
    }
    for (int i = 1;i < n;++i) {
    	while (s[i - 1] > s[i]) {
    		add1(i);
    		s[i] += k;
    	}
    }
    for (int i = 0;i < A.size();++i) {
    	int w = -1;
    	while (w + 1 < n && !(A[i] & (1ll << (w + 1))))
    		++w;
    	while (w >= k - 1) {
    		if (add2(w - k + 1))
    			--i;
    		w -= k;
    	}
    }
    while (!A.empty() && (A[0] & (1ll << (n - 1)))) {
    	for (int i = 0;!add1(i);++i) ;
    }
	if (!A.empty())
	for (int i = 0;i < (n % k);++i)
		while (!(A.back() & (1ll << i)))
			add1(i);
	while (!A.empty()) {
		for (int i = (n % k);i < n;i += k)
			add2(i);
	}
	cout << (answer.size()) << '\n';
	for (auto it : answer)
		cout << it.fi << ' ' << (it.se + 1) << '\n';
    return 0;
}

Compilation message

joiris.cpp: In function 'void G(int)':
joiris.cpp:22:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  while (A.size() <= sz)
         ~~~~~~~~~^~~~~
joiris.cpp: In function 'int add1(int)':
joiris.cpp:29:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0;i < A.size();++i)
                 ~~^~~~~~~~~~
joiris.cpp: In function 'int add2(int)':
joiris.cpp:48:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int j = 0;j < A.size() && (A[j] & (1ll << i));++j)
                  ~~^~~~~~~~~~
joiris.cpp: In function 'int main()':
joiris.cpp:84:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0;i < A.size();++i) {
                    ~~^~~~~~~~~~
joiris.cpp:66:9: warning: unused variable 'ok' [-Wunused-variable]
     int ok = 0;
         ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 540 KB Output is correct
4 Correct 2 ms 540 KB Output is correct
5 Correct 2 ms 548 KB Output is correct
6 Correct 2 ms 576 KB Output is correct
7 Correct 2 ms 576 KB Output is correct
8 Correct 2 ms 576 KB Output is correct
9 Correct 2 ms 576 KB Output is correct
10 Correct 2 ms 576 KB Output is correct
11 Correct 3 ms 576 KB Output is correct
12 Correct 2 ms 576 KB Output is correct
13 Correct 2 ms 576 KB Output is correct
14 Correct 2 ms 576 KB Output is correct
15 Correct 3 ms 576 KB Output is correct
16 Correct 3 ms 592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 592 KB Output is correct
2 Correct 2 ms 592 KB Output is correct
3 Correct 2 ms 592 KB Output is correct
4 Correct 2 ms 592 KB Output is correct
5 Correct 3 ms 636 KB Output is correct
6 Correct 3 ms 656 KB Output is correct
7 Correct 2 ms 656 KB Output is correct
8 Correct 2 ms 656 KB Output is correct
9 Correct 2 ms 668 KB Output is correct
10 Correct 2 ms 668 KB Output is correct
11 Correct 2 ms 668 KB Output is correct
12 Correct 2 ms 668 KB Output is correct
13 Correct 2 ms 668 KB Output is correct
14 Correct 2 ms 668 KB Output is correct
15 Correct 2 ms 668 KB Output is correct
16 Correct 3 ms 668 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 540 KB Output is correct
4 Correct 2 ms 540 KB Output is correct
5 Correct 2 ms 548 KB Output is correct
6 Correct 2 ms 576 KB Output is correct
7 Correct 2 ms 576 KB Output is correct
8 Correct 2 ms 576 KB Output is correct
9 Correct 2 ms 576 KB Output is correct
10 Correct 2 ms 576 KB Output is correct
11 Correct 3 ms 576 KB Output is correct
12 Correct 2 ms 576 KB Output is correct
13 Correct 2 ms 576 KB Output is correct
14 Correct 2 ms 576 KB Output is correct
15 Correct 3 ms 576 KB Output is correct
16 Correct 3 ms 592 KB Output is correct
17 Correct 2 ms 668 KB Output is correct
18 Correct 2 ms 668 KB Output is correct
19 Execution timed out 1087 ms 66524 KB Time limit exceeded
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 540 KB Output is correct
4 Correct 2 ms 540 KB Output is correct
5 Correct 2 ms 548 KB Output is correct
6 Correct 2 ms 576 KB Output is correct
7 Correct 2 ms 576 KB Output is correct
8 Correct 2 ms 576 KB Output is correct
9 Correct 2 ms 576 KB Output is correct
10 Correct 2 ms 576 KB Output is correct
11 Correct 3 ms 576 KB Output is correct
12 Correct 2 ms 576 KB Output is correct
13 Correct 2 ms 576 KB Output is correct
14 Correct 2 ms 576 KB Output is correct
15 Correct 3 ms 576 KB Output is correct
16 Correct 3 ms 592 KB Output is correct
17 Correct 2 ms 592 KB Output is correct
18 Correct 2 ms 592 KB Output is correct
19 Correct 2 ms 592 KB Output is correct
20 Correct 2 ms 592 KB Output is correct
21 Correct 3 ms 636 KB Output is correct
22 Correct 3 ms 656 KB Output is correct
23 Correct 2 ms 656 KB Output is correct
24 Correct 2 ms 656 KB Output is correct
25 Correct 2 ms 668 KB Output is correct
26 Correct 2 ms 668 KB Output is correct
27 Correct 2 ms 668 KB Output is correct
28 Correct 2 ms 668 KB Output is correct
29 Correct 2 ms 668 KB Output is correct
30 Correct 2 ms 668 KB Output is correct
31 Correct 2 ms 668 KB Output is correct
32 Correct 3 ms 668 KB Output is correct
33 Correct 2 ms 668 KB Output is correct
34 Correct 2 ms 668 KB Output is correct
35 Execution timed out 1087 ms 66524 KB Time limit exceeded
36 Halted 0 ms 0 KB -