이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define F first
#define S second
#define int long long
#define pb push_back
#define double float
using namespace std;
const int N=1e6,M=2e3,mod=1e9+7;
char x[6]={'a','b','c','d','e'};
vector<int>v;
int vis[10];
double anss=1e18;
int LL,RR;
int freq[N][6],n;
bool ok(int mid,int l){
if(l+mid>=n)
return 0;
for(int i=0;i<5;i++){
int x;
if(l==0)
x=freq[l+mid-1][i];
else
x=freq[l+mid-1][i]-freq[l-1][i];
if(vis[i]==0&&x!=0)
return 0;
}
return 1;
}
void bt(int index){
if(index==5){
for(int i=0;i<n;i++){
int l=0,r=n;
while(l<r){
int mid=(l+r+1)/2;
if(ok(mid,i))
l=mid;
else r=mid-1;
}
double num=0;
for(int i=0;i<5;i++)
if(vis[i])
num++;
double len=l;
if(num/l<anss)
anss=num/l,LL=i,RR=i+l-1;
}
return ;
}
vis[x[index]-'a']=1;
bt(index+1);
vis[x[index]-'a']=0;
bt(index+1);
}
main()
{
cin>>n;
set<int>st;
string s;
cin>>s;
for(int j=0;j<5;j++)
freq[0][j]=(j==(s[0]-'a'));
for(int i=1;i<n;i++)
for(int j=0;j<5;j++)
freq[i][j]=freq[i-1][j]+(j==(s[i]-'a'));
bt(0);
cout<<LL+1<<" "<<RR+1<<endl;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
nivelle.cpp: In function 'void bt(long long int)':
nivelle.cpp:60:20: warning: unused variable 'len' [-Wunused-variable]
60 | double len=l;
| ^~~
nivelle.cpp: At global scope:
nivelle.cpp:78:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
78 | main()
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |