답안 #127723

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
127723 2019-07-10T03:24:45 Z abacaba Zalmoxis (BOI18_zalmoxis) C++14
35 / 100
373 ms 85508 KB
#include <bits/stdc++.h>
using namespace std;

#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
#define mp make_pair
#define f first
#define se second
#define pb push_back
#define ppb pop_back
#define ll long long
#define ull unsigned long long
#define cntbit(x) __builtin_popcount(x)
#define uset unordered_set
#define umap unordered_map
#define pii pair<int, int>
#define ld long double
#define pll pair<long long, long long>

const int inf = 2e9;
const int N = 1e6 + 15;
int n, k, a[N];

struct node {
	node *prev, *next;
	int val;
	node(int val) : val(val) {
		prev = next = NULL;
	}
};

typedef node* pnode;

map <int, vector <pnode> > is;
vector <pnode> fr;

pnode root = NULL, last;
stack <pair <int, pnode> > st;

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> k;
	for(int i = 1; i <= n; ++i)
		cin >> a[i];
	root = new node(a[1]);
	is[a[1]].pb(root);
	last = root;
	for(int i = 2; i <= n; ++i) {
		pnode x = new node(a[i]);
		x->prev = last;
		last->next = x;
		last = x;
		is[a[i]].pb(x);
	}
	last = root;
	while(last && k) {
	    int now = last->val;
	    while(!st.empty() && st.top().f == now) {
	        st.pop();
	        ++now;
	    }
	    while(!st.empty() && st.top().f < now) {
	        pnode x = new node(st.top().f);
	        x->next = last;
	        x->prev = last->prev;
	        x->next->prev = x;
	        x->prev->next = x;
	        fr.pb(x);
	        int curval = x->val;
	        while(!st.empty() && st.top().f == curval)
	            st.pop(), ++curval;
	        st.push(mp(curval, x));
	        --k;
	    }
	    while(!st.empty() && st.top().f == now) {
	        st.pop();
	        ++now;
	    }
	    st.push(mp(now, last));
		last = last->next;
	}
	if(!st.empty() && st.top().f != 30) {
	    last = st.top().se;
	    pnode x = new node(st.top().f);
	    x->prev = last;
        x->prev->next = x;
        fr.pb(x);
        --k;
	}
	while(!fr.empty() && k) {
		pnode x = fr.back();
		fr.ppb();
		if(x->val <= 1)
			continue;
		pnode a = new node(x->val - 1), b = new node(x->val - 1);
		a->prev = x->prev;
		a->next = b;
		b->prev = a;
		b->next = x->next;
		if(b->next)
    		b->next->prev = b;
    	if(a->prev)
    		a->prev->next = a;
		fr.pb(a);
		fr.pb(b);
		--k;
	}
	while(root) {
		cout << root->val << ' ';
		root = root->next;
	}
    return 0;
}

Compilation message

zalmoxis.cpp: In function 'int main()':
zalmoxis.cpp:102:6: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
      if(a->prev)
      ^~
zalmoxis.cpp:104:3: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   fr.pb(a);
   ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 251 ms 47716 KB Output is correct
2 Correct 256 ms 47616 KB Output is correct
3 Correct 249 ms 47740 KB Output is correct
4 Correct 251 ms 47620 KB Output is correct
5 Correct 248 ms 47768 KB Output is correct
6 Correct 249 ms 47696 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 247 ms 47648 KB not a zalsequence
2 Incorrect 373 ms 85508 KB Expected EOF
3 Correct 254 ms 47680 KB Output is correct
4 Incorrect 248 ms 47640 KB not a zalsequence
5 Incorrect 250 ms 47636 KB not a zalsequence
6 Incorrect 246 ms 47620 KB not a zalsequence
7 Incorrect 256 ms 47772 KB not a zalsequence
8 Incorrect 250 ms 47796 KB not a zalsequence
9 Incorrect 246 ms 48028 KB not a zalsequence
10 Incorrect 212 ms 56744 KB not a zalsequence
11 Incorrect 222 ms 52660 KB not a zalsequence
12 Incorrect 2 ms 376 KB Unexpected end of file - int32 expected
13 Incorrect 2 ms 380 KB Unexpected end of file - int32 expected
14 Incorrect 2 ms 376 KB Unexpected end of file - int32 expected