AcWing 4401. 找回数组
原题链接
中等
作者:
落拓Leisure
,
2022-11-25 20:23:39
,
所有人可见
,
阅读 130
#include <iostream>
#include <set>
using namespace std;
const int N = 1e3 + 10;
int s[N];
int n;
string str;
set<int> S;
int main()
{
cin >> n;
for(int i = 1; i <= n; i ++ ) cin >> s[i];
for(int i = 1; i <= n; i ++ ) str.insert(i - 1, 1, s[i] - s[i - 1] + '0');
for(int i = 1; i < n; i ++ )
{
bool flag;
for(int j = i; j < n; j += i)
{
flag = true;
if(n - j < i && str.substr(j, n - j) != str.substr(0, n - j))
flag = false;
else if(n - j >= i && str.substr(j, i) != str.substr(0, i))
flag = false;
if(!flag) break;
}
if(flag) S.insert(i);
}
S.insert(n);
cout << S.size() << endl;
for(auto x : S) cout << x << ' ';
return 0;
}