Pagini recente » Cod sursa (job #2632781) | Cod sursa (job #2984503) | Cod sursa (job #33512) | Cod sursa (job #445881) | Cod sursa (job #3145600)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("perb.in");
ofstream fout("perb.out");
int n,q,best[605][605];
int v[605];
int f[605][5];
int main()
{
ios_base::sync_with_stdio(false);
fin.tie(0);
fin>>n>>q;
for(int i=1;i<=n;i++)
{
char c;
fin>>c;
if(c=='A')
v[i]=1;
if(c=='C')
v[i]=2;
if(c=='G')
v[i]=3;
if(c=='T')
v[i]=4;
}
for(int i=1;i<=n;i++)
for(int j=i;j<=n;j++)
best[i][j]=1e9;
for(int nums=1;nums<=n;nums++)
{
for(int i=1;i<=n;i++)
{
for(int j=0;j<=nums;j++)
{
f[j][1]=0;
f[j][2]=0;
f[j][3]=0;
f[j][4]=0;
}
int rez=0;
for(int j=i;j<=n;j++)
{
int rest=j%nums;
int x=max(max(f[rest][1],f[rest][2]),max(f[rest][3],f[rest][4]));
rez-=x;
f[rest][v[j]]++;
x=max(max(f[rest][1],f[rest][2]),max(f[rest][3],f[rest][4]));
rez+=x;
int lg=j-i+1;
if(lg>nums&&lg%nums==0)
best[i][j]=min(best[i][j],lg-rez);
}
}
}
while(q--)
{
int l,r;
fin>>l>>r;
fout<<best[l][r]<<'\n';
}
return 0;
}