QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#292748#7119. Longest TripInsert_Username_Here0 3ms3796kbC++203.6kb2023-12-28 12:34:142023-12-28 12:34:16

Judging History

你现在查看的是测评时间为 2023-12-28 12:34:16 的历史记录

  • [2024-04-28 09:14:06]
  • 管理员手动重测本题所有提交记录
  • 测评结果:0
  • 用时:13ms
  • 内存:4104kb
  • [2023-12-28 12:34:16]
  • 评测
  • 测评结果:0
  • 用时:3ms
  • 内存:3796kb
  • [2023-12-28 12:34:14]
  • 提交

answer

#include "longesttrip.h"
#include <bits/stdc++.h>
#define f first
#define s second
#define mp make_pair
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
// cope counter = 2254
#pragma GCC optimize("O3,unroll-loops,Ofast")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")

map<pair<vector<int>, vector<int>>, bool> kms;

bool qry(vector<int> a, vector<int> b) {
	if(!kms.contains(mp(a, b))) kms[mp(a, b)] = are_connected(a, b);
	return kms[mp(a, b)];
}

vector<int> longest_trip(int n, int D) {
	kms.clear();
	vector<int> l1, l2, l3, a, b, c, d;
	vector<int> idfk;
	for(int i = 0; i < n; i++) idfk.push_back(i);
	mt19937 rng(std::chrono::steady_clock::now().time_since_epoch().count());
	shuffle(idfk.begin(), idfk.end(), rng);
	l1.push_back(idfk[0]), l2.push_back(idfk[1]);
	for(int i = 2; i + 1 < n; i+= 2) {
		a.clear(), a.push_back(l1.back());
		b.clear(), b.push_back(l2.back());
		c.clear(), c.push_back(idfk[i]);
		d.clear(), d.push_back(idfk[i + 1]);
		if(qry(c, d)) {
			if(qry(a, c)) a.push_back(c[0]), a.push_back(d[0]);
			else if(qry(b, c)) b.push_back(c[0]), b.push_back(d[0]);
			else {
				for(int i = l2.size() - 1; i >= 0; i--) l1.push_back(l2[i]);
				l2.clear();
				l2.push_back(c[0]), l2.push_back(d[0]);
			}
		} else if(qry(a, c)) {
			l1.push_back(c[0]);
			if(qry(b, c)) {
				for(int i = l2.size() - 1; i >= 0; i--) l1.push_back(l2[i]);
				l2.clear();
				l2.push_back(d[0]);
			} else {
				l2.push_back(d[0]);
			}
		} else {
			l1.push_back(d[0]);
			if(qry(b, d)) {
				for(int i = l2.size() - 1; i >= 0; i--) l1.push_back(l2[i]);
				l2.clear();
				l2.push_back(c[0]);
			} else {
				l2.push_back(c[0]);
			}
		}
	}
	if(n % 2) {
		a.clear(), a.push_back(l1.back());
		b.clear(), b.push_back(l2.back());
		c.clear(), c.push_back(idfk[n - 1]);
		if(qry(a, c)) a.push_back(c[0]);
		else if(qry(b, c)) b.push_back(c[0]);
		else {
			for(int i = l2.size() - 1; i >= 0; i--) l1.push_back(l2[i]);
			l2.clear();
			l2.push_back(c[0]);
		}
	}
	if(!qry(l1, l2)) {
		if(l1.size() > l2.size()) return l1;
		return l2;
	}
	a.clear(), a.push_back(l1.back());
	b.clear(), b.push_back(l2.back());
	if(qry(a, b)) {
		for(int i = l2.size() - 1; i >= 0; i--) l1.push_back(l2[i]);
		return l1;
	}
	a.clear(), a.push_back(l1.back());
	b.clear(), b.push_back(l2[0]);
	if(qry(a, b)) {
		for(int i = 0; i < l2.size(); i++) l1.push_back(l2[i]);
		return l1;
	}
	a.clear(), a.push_back(l1[0]);
	b.clear(), b.push_back(l2.back());
	if(qry(a, b)) {
		for(int i = 0; i < l1.size(); i++) l2.push_back(l1[i]);
		return l2;
	}
	a.clear(), a.push_back(l1[0]);
	b.clear(), b.push_back(l2[0]);
	if(qry(a, b)) {
		l3.clear();
		for(int i = l1.size() - 1; i >= 0; i--) l3.push_back(l1[i]);
		for(int i = 0; i < l2.size(); i++) l3.push_back(l2[i]);
		return l3;
	}
	int l = 0, r = l2.size(), mid;
	while(l < r) {
		mid = (l + r) / 2;
		if(l == mid) break;
		l3.clear();
		for(int i = l; i < mid; i++) l3.push_back(l2[i]);
		if(l3.size() > 0 && qry(l1, l3)) r = mid;
		else l = mid;
	}
	int bk = r - 1;
	l = 0, r = l1.size();
	b.clear(), b.push_back(l2[bk]);
	while(l < r) {
		mid = (l + r) / 2;
		if(l == mid) break;
		l3.clear();
		for(int i = l; i < mid; i++) l3.push_back(l1[i]);
		if(l3.size() > 0 && qry(b, l3)) r = mid;
		else l = mid;
	}
	a.clear(), a.push_back(l1[mid]);
	l3.clear();
	for(int i = r; i < l1.size(); i++) l3.push_back(l1[i]);
	for(int i = 0; i < r; i++) l3.push_back(l1[i]);
	for(int i = bk; i < l2.size(); i++) l3.push_back(l2[i]);
	for(int i = 0; i < bk; i++) l3.push_back(l2[i]);
	return l3;
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3700kb

input:

341
3 3
1
1

output:

3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 2 1
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 2 0
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
1 2 2 0

result:

wrong answer 

Subtask #2:

score: 0
Wrong Answer

Test #6:

score: 0
Wrong Answer
time: 1ms
memory: 3704kb

input:

341
3 2
1
1

output:

3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 0 1
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 0 2
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
1 2 0 2

result:

wrong answer 

Subtask #3:

score: 0
Wrong Answer

Test #19:

score: 25
Accepted
time: 3ms
memory: 3796kb

input:

341
3 1
1
1
1
3 1
1
1
1
3 1
1
1
1
3 1
1
1
1
3 1
1
1
1
3 1
1
1
1
3 1
1
1
1
3 1
1
1
1
3 1
1
1
1
3 1
1
1
1
3 1
1
1
1
3 1
1
1
1
3 1
1
1
1
3 1
1
1
1
3 1
1
1
1
3 1
1
1
1
3 1
1
1
1
3 1
1
1
1
3 1
1
1
1
3 1
1
1
1
3 1
1
1
1
3 1
1
1
1
3 1
1
1
1
3 1
1
1
1
3 1
1
1
1
3 1
1
1
1
3 1
1
1
1
3 1
1
1
1
3 1
1
1
1
3 1
1
...

output:

3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 1 0
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 1 2
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
1 2 1 2
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 1 2
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 1 0
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
1 2 1 0
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 1 0
3kC...

result:

ok 

Test #20:

score: -25
Wrong Answer
time: 1ms
memory: 3788kb

input:

103
10 1
1
1
1
1
1
1
1
1
1

output:

3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 4 8
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 3 4
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 2 0
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 3 2
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 7 9
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 3 7
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 5 6...

result:

wrong answer 

Subtask #4:

score: 0
Wrong Answer

Test #83:

score: 0
Wrong Answer
time: 0ms
memory: 3796kb

input:

341
3 1
1
1

output:

3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 1 0
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 1 2
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
1 2 1 2

result:

wrong answer