QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#475387#6748. Spin the Wheel1903331632TL 0ms3492kbC++201.7kb2024-07-13 14:25:322024-07-13 14:25:32

Judging History

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

  • [2024-07-13 14:25:32]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3492kb
  • [2024-07-13 14:25:32]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e6 + 10;
bool isSameCycle(const std::vector<int> &seq1, const std::vector<int> &seq2)
{
	if (seq1.size() != seq2.size())
		return false;

	int n = seq1.size();
	// 将第一个序列复制一遍连接起来
	std::vector<int> doubledSeq1(seq1.begin(), seq1.end());
	doubledSeq1.insert(doubledSeq1.end(), seq1.begin(), seq1.end());

	// 将第二个序列转化为字符串形式,方便查找子串
	std::string strSeq2;
	for (int num : seq2)
	{
		strSeq2 += std::to_string(num) + ",";
	}

	// 将第一个序列的两倍序列转化为字符串形式
	std::string strDoubledSeq1;
	for (int num : doubledSeq1)
	{
		strDoubledSeq1 += std::to_string(num) + ",";
	}

	// 查找第二个序列是否是第一个序列两倍序列的子串
	if (strDoubledSeq1.find(strSeq2) != std::string::npos)
	{
		return true;
	}

	return false;
}
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin >> n;
	vector<int> v1, v2;
	for (int i = 1; i <= n; i++)
	{
		int x;
		cin >> x;
		v1.push_back(x);
	}
	for (int i = 0; i < n; i++)
	{
		v2.push_back(0);
	}
	for (int i = 0; i < n; i++)
	{
		// for (int j = 0; j < n; j++)
		// {
		// 	cout << v2[j] << " ";
		// }
		// cout << endl;
		if (isSameCycle(v1, v2))
		{
			bool is = true;
			for (int j = 0; j < n; j++)
			{
				if (v1[j] != v2[j])
					is = false;
			}
			if (is)
			{
				cout << i << endl;
				return 0;
			}
			else
			{
				cout << i + 1 << endl;
				return 0;
			}
		}
		for (int j = 0; j < n; j++)
		{
			v2[j] += j;
			if (v2[j] >= n)
				v2[j] -= n;
		}
	}
	cout << -1 << endl;
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3492kb

input:

5
1 3 0 2 4

output:

3

result:

ok 1 number(s): "3"

Test #2:

score: -100
Time Limit Exceeded

input:

100000
0 55555 11110 66665 22220 77775 33330 88885 44440 99995 55550 11105 66660 22215 77770 33325 88880 44435 99990 55545 11100 66655 22210 77765 33320 88875 44430 99985 55540 11095 66650 22205 77760 33315 88870 44425 99980 55535 11090 66645 22200 77755 33310 88865 44420 99975 55530 11085 66640 221...

output:


result: