Submission #1273261

#TimeUsernameProblemLanguageResultExecution timeMemory
1273261SmuggingSpunLampice (COCI21_lampice)C++20
50 / 50
1 ms348 KiB
#include<bits/stdc++.h>
#define taskname "A"
using namespace std;
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	if(fopen(taskname".inp", "r")){
		freopen(taskname".inp", "r", stdin);
	}
	int n, k;
	cin >> n >> k;
	vector<int>a(n + 1);
	for(int i = 1; i <= n; i++){
		cin >> a[i];
	}
	for(int len = 1; len <= n; len++){
		if(len % k == 0){
			for(int l = n - len + 1; l > 0; l--){
				int r = l + len - 1, L = len / k;
				bool f = true;
				for(int i = l; i + L - 1 <= r; i += L){
					for(int j = 0; j < L; j++){
						if(a[l + j] != a[i + j]){
							f = false;
							break;
						}
					}
				}
				if(f){
					cout << L << "\n";
					for(int j = 0; j < L; j++){
						cout << a[l + j] << " ";
					}
					return 0;
				}
			}
		}
	}
	cout << -1;
}

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:7:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    7 |                 freopen(taskname".inp", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...