P1650 20分TLE 求助
  • 板块灌水区
  • 楼主maxiaoteng2021
  • 当前回复5
  • 已保存回复5
  • 发布时间2022/5/3 23:36
  • 上次更新2023/10/28 02:14:34
查看原帖
P1650 20分TLE 求助
615196
maxiaoteng2021楼主2022/5/3 23:36

今天熬夜赶P1650,20分TLE,总是上不去。求哪位大神帮忙看看

#include<bits/stdc++.h>
typedef long long LL;
typedef unsigned int uint;
typedef unsigned long long ull;
#define tab putchar('\t')
#define enter putchar('\n')
#define il inline
#define fi first
#define se second
using namespace std;
int tianji[100001], qiwang[100001];
int n, ans = 0;
bool cmp(int x, int y){
	return x > y;
}
int read(){
	int x = 0, f = 1;
	char c = getchar();
	while(c < '0' || c > '9'){
		if(c == '-'){
			f = -1;
		}
		c = getchar();
	}
	while(c >= '0' && c <= '9'){
		x = x*10+c-'0';
		c = getchar();
	}
	return x*f;
}
signed main() {
	//
	cin >> n;
	for(int i = 1; i <= n; ++ i){
		tianji[i] = read();
	}
	for(int i = 1; i <= n; ++ i){
		qiwang[i] = read();
	}
	sort(tianji + 1, tianji + 1 + n, cmp);
	sort(qiwang + 1, qiwang + 1 + n, cmp);
	for(int i = 1, i2 = n, j = 1, j2 = n; i <= i2, j <= j2;){
		if(tianji[i] > qiwang[j]){
			++ ans;
			++ i;
			++ j;
		}
		else if(tianji[i] < qiwang[j]){
			-- ans;
			++ j;
			-- i2;
		}
		else{
			if(tianji[i2] > qiwang[j2]){
				++ ans;
				-- i2;
				-- j2;
			}
			else{
				if(tianji[i2] < qiwang[j])
				{
					--ans; -- i2; ++ j;
				}
			}
		}
	}
	cout << 200*ans;
	return 0;
}

2022/5/3 23:36
加载中...