답안 #30111

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
30111 2017-07-22T06:30:05 Z 서규호(#1248) Tree Rotations (POI11_rot) C++14
0 / 100
0 ms 1848 KB
#include <bits/stdc++.h>
#include <unistd.h>

#define pii pair<int,int>
#define pll pair<lld,lld>
#define pb push_back
#define next nextt
#define left leftt
#define right rightt
#define lld long long
#define Inf 1000000000
#define mod 1000000007
#define Linf 1000000000000000000LL
#define get gett

using namespace std;

int N,rear; lld ans;
int left[2000002],right[200002];
set<int> S[2000002];

void dfs(int x){
	int in;
	scanf("%d",&in);
	if(in == 0){
		rear++;
		left[x] = rear;
		dfs(rear);
	}else{
		left[x] = in;
	}
	scanf("%d",&in);
	if(in == 0){
		rear++;
		right[x] = rear;
		dfs(rear);
	}else{
		right[x] = in;
	}
}

void calc(int x){
	if(1 <= x && x <= N){
		S[x].insert(x);
		return;
	}
	calc(left[x]);
	calc(right[x]);
	set<int> tmp;
	swap(S[x],S[left[x]]);
	swap(tmp,S[right[x]]);
	if(S[x].size() < tmp.size()) swap(S[x],tmp);
	int cnt = 0; lld sum = 0;
	auto it = S[x].begin();
	for(auto &i : tmp){
		while(1){
			if(it != S[x].end() && (*it) < i){
				cnt++;
				it++;
			}else break;
		}
		sum += cnt;
	}
	lld calctmp = (lld)S[x].size()*(lld)tmp.size();
	ans += min(sum,calctmp-sum);
	for(auto &i : tmp) S[x].insert(i);
}

int main(){
    //freopen("input.txt","r",stdin);
	int in;
	scanf("%d",&N);
	scanf("%d",&in);
	if(N == 1){
		puts("0");
		return 0;
	}
	rear = N;
	return 0;
	dfs(0);
	calc(0);
	printf("%lld\n",ans);

	return 0;
}

Compilation message

rot.cpp: In function 'void dfs(int)':
rot.cpp:24:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&in);
                 ^
rot.cpp:32:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&in);
                 ^
rot.cpp: In function 'int main()':
rot.cpp:72:16: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&N);
                ^
rot.cpp:73:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&in);
                 ^
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 1848 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 1848 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 1848 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 1848 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 1848 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 1848 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 1848 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 1848 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 1848 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 1848 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 1848 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -