Submission #70228063
Source Code Expand
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main()
{
int n,k;
scanf("%d %d", &n, &k);
char kata[n + 10];
scanf("%s", kata);
vector <int> vect;
int maxcount = 0;
for(int i = 0 ; i <= n - k ; i++)
{
int ct = 1;
for(int j = i + 1 ; j <= n - k ; j++)
{
ct++;
for(int t = 0 ; t < k ; t++)
{
if(kata[i + t] != kata[j + t])
{
ct--;
break;
}
}
}
if(ct > maxcount)
{
maxcount = ct;
vect.clear();
}
if(ct == maxcount)
vect.push_back(i);
}
vector <string> prt;
for(int i = 0 ; i < vect.size() ; i++)
{
string temp = "";
for(int j = vect[i] ; j < vect[i] + k ; j++)
temp += kata[j];
prt.push_back(temp);
}
sort(prt.begin(), prt.end());
printf("%d\n", maxcount);
for(int i = 0 ; i < prt.size() ; i++)
cout << prt[i] << " ";
printf("\n");
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | B - Most Frequent Substrings |
| User | MichaelH |
| Language | C++ 17 (gcc 12.2) |
| Score | 200 |
| Code Size | 1193 Byte |
| Status | AC |
| Exec Time | 1 ms |
| Memory | 3884 KiB |
Compile Error
Main.cpp: In function ‘int main()’:
Main.cpp:42:23: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::vector<int>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
42 | for(int i = 0 ; i < vect.size() ; i++)
| ~~^~~~~~~~~~~~~
Main.cpp:52:23: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::vector<std::__cxx11::basic_string<char> >::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
52 | for(int i = 0 ; i < prt.size() ; i++)
| ~~^~~~~~~~~~~~
Main.cpp:10:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
10 | scanf("%d %d", &n, &k);
| ~~~~~^~~~~~~~~~~~~~~~~
Main.cpp:12:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
12 | scanf("%s", kata);
| ~~~~~^~~~~~~~~~~~
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 200 / 200 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | 00-sample-01.txt, 00-sample-02.txt, 00-sample-03.txt |
| All | 00-sample-01.txt, 00-sample-02.txt, 00-sample-03.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 00-sample-01.txt | AC | 1 ms | 3816 KiB |
| 00-sample-02.txt | AC | 1 ms | 3576 KiB |
| 00-sample-03.txt | AC | 1 ms | 3704 KiB |
| 01-01.txt | AC | 1 ms | 3620 KiB |
| 01-02.txt | AC | 1 ms | 3884 KiB |
| 01-03.txt | AC | 1 ms | 3816 KiB |
| 01-04.txt | AC | 1 ms | 3680 KiB |
| 01-05.txt | AC | 1 ms | 3616 KiB |
| 01-06.txt | AC | 1 ms | 3680 KiB |
| 01-07.txt | AC | 1 ms | 3676 KiB |
| 01-08.txt | AC | 1 ms | 3684 KiB |
| 01-09.txt | AC | 1 ms | 3812 KiB |
| 01-10.txt | AC | 1 ms | 3684 KiB |
| 01-11.txt | AC | 1 ms | 3880 KiB |
| 01-12.txt | AC | 1 ms | 3752 KiB |
| 01-13.txt | AC | 1 ms | 3808 KiB |
| 01-14.txt | AC | 1 ms | 3876 KiB |
| 01-15.txt | AC | 1 ms | 3664 KiB |
| 01-16.txt | AC | 1 ms | 3808 KiB |
| 01-17.txt | AC | 1 ms | 3812 KiB |
| 01-18.txt | AC | 1 ms | 3680 KiB |
| 01-19.txt | AC | 1 ms | 3684 KiB |