답안 #826473

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
826473 2023-08-15T15:47:23 Z QwertyPi Necklace (Subtask 1-3) (BOI19_necklace1) C++14
0 / 85
1500 ms 212 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;

struct answer{
	int a, x, y;
};

bool are_equal(const string& s, const string& t){
	if(s.length() != t.length()) return false;
	for(int i = 0; i < s.length(); i++){
		bool eq = true;
		for(int j = 0; j < s.length(); j++){
			eq &= s[j] == t[(i + j) % s.length()];
		}
		if(eq) return true;
	}
	return false;
}

answer query(const string& s, const string& t){
	int n = s.size(), m = t.size();
	answer ans {-1, 0, 0};
	for(int l = 1; l <= min(n, m); l++){
		for(int i = 0; i <= n - l; i++){
			for(int j = 0; j <= m - l; j++){
				bool ok = are_equal(s.substr(i, l), t.substr(j, l));
				if(ok){
					ans = answer {l, i, j};
				}
			}
		}
	}
	return ans;
}

int32_t main(){
	string s, t; cin >> s >> t;
	answer a1 = query(s, t);
	reverse(t.begin(), t.end());
	answer a2 = query(s, t); a2.y = t.size() - (a2.y + a2.a);

	answer ans; ans.a = -1;
	if(a1.a > ans.a) ans = a1;
	if(a2.a > ans.a) ans = a2;
	cout << ans.a << endl;
	cout << ans.x << ' ' << ans.y << endl; 
}

Compilation message

necklace.cpp: In function 'bool are_equal(const string&, const string&)':
necklace.cpp:11:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 |  for(int i = 0; i < s.length(); i++){
      |                 ~~^~~~~~~~~~~~
necklace.cpp:13:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |   for(int j = 0; j < s.length(); j++){
      |                  ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1577 ms 212 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1577 ms 212 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1577 ms 212 KB Time limit exceeded
2 Halted 0 ms 0 KB -