Submission #258080

# Submission time Handle Problem Language Result Execution time Memory
258080 2020-08-05T10:26:21 Z Namnamseo Swap (BOI16_swap) C++17
100 / 100
131 ms 30332 KB
#include <bits/stdc++.h>
using namespace std;
void read(int& x){ scanf("%d",&x); }
template<typename T,typename... Args>
void read(T& a,Args&... b){ read(a); read(b...); }
#define all(x) (x).begin(),(x).end()
#define pb push_back
const int inf = 1e9;

int n;
int arr[200010];

struct kumi {
	vector<kumi*> child;
	int val;
	int pick(){
		if(val) return val;
		int ret=inf;
		for(kumi* c : child) ret=min(ret, c->pick());
		return ret;
	}
	
	void poll(int x){
		if(val){
			val = inf;
		} else {
			int n=child.size();
			for(int i=0; i<n; ++i) if(child[i]->pick() == x){
				child[i]->poll(x);
				child.erase(child.begin() + i);
				break;
			}
		}
	}
};

kumi* my[200010];

int main()
{
    read(n);
    for(int i=1; i<=n; ++i) read(arr[i]);
    
    for(int i=1; i<=n; ++i){
		kumi* pt = new kumi();
		pt->val = arr[i];
		kumi* p = new kumi();
		p->val=0; p->child.pb(pt);
		my[i] = p;
    }
    
    for(int i=1; i<=n; ++i){
		int lv=inf, rv=inf;
		if(i*2 <= n) lv=arr[i*2];
		if(i*2+1 <= n) rv=arr[i*2+1];
		assert(my[i]->child.size());
		int mv=my[i]->pick();
		int min_val = min({lv, rv, mv});
		printf("%d ", min_val);
		if(min_val == mv){
			my[i]->poll(mv);
		} else if(min_val == lv){
			my[i*2] = my[i];
		} else {
			my[i*2]->child.pb(my[i]);
			my[i*2+1] = my[i*2];
		}
    }
    return 0;
}

Compilation message

swap.cpp: In function 'void read(int&)':
swap.cpp:3:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
 void read(int& x){ scanf("%d",&x); }
                    ~~~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 512 KB Output is correct
12 Correct 1 ms 512 KB Output is correct
13 Correct 1 ms 512 KB Output is correct
14 Correct 1 ms 512 KB Output is correct
15 Correct 1 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 512 KB Output is correct
12 Correct 1 ms 512 KB Output is correct
13 Correct 1 ms 512 KB Output is correct
14 Correct 1 ms 512 KB Output is correct
15 Correct 1 ms 512 KB Output is correct
16 Correct 22 ms 7808 KB Output is correct
17 Correct 23 ms 7800 KB Output is correct
18 Correct 22 ms 7800 KB Output is correct
19 Correct 29 ms 7808 KB Output is correct
20 Correct 30 ms 7800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 512 KB Output is correct
12 Correct 1 ms 512 KB Output is correct
13 Correct 1 ms 512 KB Output is correct
14 Correct 1 ms 512 KB Output is correct
15 Correct 1 ms 512 KB Output is correct
16 Correct 22 ms 7808 KB Output is correct
17 Correct 23 ms 7800 KB Output is correct
18 Correct 22 ms 7800 KB Output is correct
19 Correct 29 ms 7808 KB Output is correct
20 Correct 30 ms 7800 KB Output is correct
21 Correct 103 ms 30200 KB Output is correct
22 Correct 97 ms 30200 KB Output is correct
23 Correct 91 ms 30332 KB Output is correct
24 Correct 131 ms 30328 KB Output is correct
25 Correct 119 ms 30328 KB Output is correct