QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#62023#140. Palembang Bridges Land_ER0 2ms3792kbC++143.3kb2022-11-16 23:36:232022-11-16 23:36:26

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-11-16 23:36:26]
  • 评测
  • 测评结果:0
  • 用时:2ms
  • 内存:3792kb
  • [2022-11-16 23:36:23]
  • 提交

answer

#include <bits/stdc++.h>
#define u32 unsigned int
#define i64 long long int
#define u64 unsigned long long int
#define N 100005
int k, nn, n;
int s[N], t[N];
i64 base;
void swap(int &a, int &b) {
	int c = a;
	a = b;
	b = c;
	return;
}
int min(int a, int b) {
	return a < b ? a : b;
}
int abs(int x) {
	return x >= 0 ? x : -x;
}
void init(void) {
	char p[5], q[5];
	scanf("%d%d", &k, &nn);
	for(int i = 1; i <= nn; ++ i) {
		++ n;
		scanf("%s%d%s%d", p, s + n, q, t + n);
		base += abs(s[n] - t[n]);
		if(p[0] == q[0]) {
			-- n;
			continue;
		}
		++ base;
		if(s[i] > t[i])
			swap(s[i], t[i]);
	}
	return;
}
namespace subtask1 {
	void solve(void) {
		int a[N<<1];
		for(int i = 1; i <= n; ++ i)
			a[i * 2 - 1] = s[i], a[i * 2] = t[i];
		std::sort(a + 1, a + n * 2 + 1);
		i64 ans = 0x7f7f7f7f7f7f7f7fll;
		for(int i = 1; i <= n * 2; ++ i) {
			i64 now = 0;
			for(int j = 1; j <= n; ++ j) {
				if(a[i] < s[j])
					now += 2ll * (s[j] - a[i]);
				else if(a[i] > t[j])
					now += 2ll * (a[i] - t[j]);
			}
			if(now < ans)
				ans = now;
		}
		printf("%lld", ans + base);
		return;
	}
}
namespace subtask2 {
	void solve(void) {
		int a[N<<1];
		for(int i = 1; i <= n; ++ i)
			a[i * 2 - 1] = s[i], a[i * 2] = t[i];
		std::sort(a + 1, a + n * 2 + 1);
		i64 ans = 0x7f7f7f7f7f7f7f7fll;
		for(int i = 1; i <= n * 2; ++ i) {
			for(int j = i + 1; j <= n * 2; ++ j) {
				i64 now = 0;
				for(int w = 1; w <= n; ++ w) {
					if((s[w] <= a[i] && a[i] <= t[w]) || (s[w] <= a[j] && a[j] <= t[w]))
						continue;
					now += min(min(abs(s[w] - a[i]), abs(t[w] - a[i])), min(abs(s[w] - a[j]), abs(t[w] - a[j])));
				}
				if(now < ans)
					ans = now;
			}
		}
		printf("%lld", ans + base);
		return;
	}
}
namespace subtask3 {
	struct node1 {
		int id;
		node1(void) {
			return;
		}
		node1(int a) {
			id = a;
			return;
		}
		bool operator<(const node1 &x) const {
			return s[id] > s[x.id];
		}
	};
	struct node2 {
		int id;
		node2(void) {
			return;
		}
		node2(int a) {
			id = a;
			return;
		}
		bool operator<(const node2 &x) const {
			return t[id] > t[x.id];
		}
	};
	void solve(void) {
		int a[N<<1];
		std::priority_queue<node1> p;
		std::priority_queue<node2> q;
		for(int i = 1; i <= n; ++ i)
			a[i * 2 - 1] = s[i], a[i * 2] = t[i];
		std::sort(a + 1, a + n * 2 + 1);
		int x = std::unique(a + 1, a + n * 2 + 1) - a - 1;
		int l = 0, r = n;
		int last = 0;
		i64 suml = 0, sumr = 0;
		for(int i = 1; i <= n; ++ i)
			sumr += s[i], p.push(node1(i));
		i64 ans = sumr;
		for(int i = 1; i < x; ++ i) {
			suml += 1ll * (a[i] - last) * l;
			sumr -= 1ll * (a[i] - last) * r;
			while(!p.empty()) {
				int w = p.top().id;
				if(s[w] > a[i])
					break;
				p.pop();
				q.push(w);
				-- r;
			}
			while(!q.empty()) {
				int w = q.top().id;
				if(t[w] > a[i])
					break;
				q.pop();
				++ l;
			}
			if(suml + sumr < ans)
				ans = suml + sumr;
			last = a[i];
		}
		printf("%lld", ans * 2 + base);
		return;
	}
}
void solve(void) {
	if(k == 1) {
		if(n > 1000)
			subtask3::solve();
		else
			subtask1::solve();
	}
	else
		subtask2::solve();
	return;
}
int main(void) {
	//freopen("input.txt", "r", stdin);
	//freopen("C.txt", "w", stdout);
	init();
	solve();
	return 0;
}

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 3532kb

input:

1 1
B 426311872 B 741424667

output:

9187201950750850266

result:

wrong answer 1st lines differ - expected: '315112795', found: '9187201950750850266'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Wrong Answer

Test #22:

score: 0
Wrong Answer
time: 2ms
memory: 3792kb

input:

2 1
B 822190955 B 309099167

output:

9187201950948829259

result:

wrong answer 1st lines differ - expected: '513091788', found: '9187201950948829259'

Subtask #4:

score: 0
Skipped

Dependency #3:

0%

Subtask #5:

score: 0
Skipped

Dependency #4:

0%