This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define int long long
#define float double
#define pb push_back
#define F first
#define S second
#define T int t; cin >> t; while(t--)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
/// Benzema is the best player in the world
const int N = 1e6 + 6;
const int M = 1e3 + 3;
const int mod = 1e9 + 7;
const int inf = 1e9;
const int dx[] = {-1, 1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const int LOG = 25;
int n, k, a[N];
vector<int> ans, v;
bool check() {
if (v.size() % k) return 0;
bool ok = 1;
vector<int> vv;
for(int i = 0; i < v.size() / k; i++) vv.push_back(v[i]);
vector<int> vvv;
for(int i = v.size() / k; i < v.size(); i += v.size() / k) {
for(int j = i; j < i + v.size() / k; j++) vvv.push_back(v[j]);
ok &= vvv == vv;
vvv.clear();
}
return ok;
}
main() {
IOS
cin >> n >> k;
for(int i = 1; i <= n; i++) cin >> a[i];
for(int i = 1; i <= n; i++) {
for(int j = i; j <= n; j++) {
v.push_back(a[j]);
if (check() && v.size() > ans.size()) ans = v;
}
v.clear();
}
if (ans.size() == 0) {
cout << -1;
return 0;
}
cout << ans.size() / k << '\n';
for(int i = 0; i < ans.size() / k; i++) cout << ans[i] << ' ';
}
Compilation message (stderr)
Main.cpp: In function 'bool check()':
Main.cpp:26:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'long long unsigned int' [-Wsign-compare]
26 | for(int i = 0; i < v.size() / k; i++) vv.push_back(v[i]);
| ~~^~~~~~~~~~~~~~
Main.cpp:28:33: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
28 | for(int i = v.size() / k; i < v.size(); i += v.size() / k) {
| ~~^~~~~~~~~~
Main.cpp:29:26: warning: comparison of integer expressions of different signedness: 'long long int' and 'long long unsigned int' [-Wsign-compare]
29 | for(int j = i; j < i + v.size() / k; j++) vvv.push_back(v[j]);
| ~~^~~~~~~~~~~~~~~~~~
Main.cpp: At global scope:
Main.cpp:36:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
36 | main() {
| ^~~~
Main.cpp: In function 'int main()':
Main.cpp:52:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'long long unsigned int' [-Wsign-compare]
52 | for(int i = 0; i < ans.size() / k; i++) cout << ans[i] << ' ';
| ~~^~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |