QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#309627#8025. FibonacciPetroTarnavskyi#WA 3ms3792kbC++201.2kb2024-01-20 19:19:222024-01-20 19:19:23

Judging History

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

  • [2024-01-20 19:19:23]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:3792kb
  • [2024-01-20 19:19:22]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;

void solve()
{
	int n, k;
	cin >> n >> k;
	VI a(k), b(k);
	FOR (i, 0, k)
		cin >> a[i];
	FOR (i, 0, k)
		cin >> b[i];
	sort(ALL(a));
	sort(ALL(b));
	int ans = n;
	FOR (i, 0, k)
	{
		vector<PII> c;
		FOR (j, 0, k)
		{
			int x = (b[(i + j) % k] - a[j] + n) % n;
			int y = x == 0 ? 0 : n - x;
			if (x != 0)
				c.PB(MP(x, y));
		}
		if (c.empty())
		{
			ans = 0;
			break;
		}
		sort(ALL(c));
		FOR (j, 0, SZ(c) - 1)
		{
			ans = min(ans, c[j].F + c[j + 1].S + min(c[j].F, c[j + 1].S));
		}
		ans = min(ans, c[0].S);
		ans = min(ans, c[SZ(c) - 1].F);
	}
	cout << ans << '\n';
	
}

int main()
{
	ios::sync_with_stdio(0); 
	cin.tie(0);
	cout << fixed << setprecision(15);
	
	int t;
	cin >> t;
	while (t--)
	{
		solve();
	}
	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3792kb

input:

1

output:

0

result:

ok answer is '0'

Test #2:

score: -100
Wrong Answer
time: 3ms
memory: 3784kb

input:

2

output:

0
0

result:

wrong output format Extra information in the output file