이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define endl '\n'
#define pb push_back
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ii = pair<int,int>;
using iii = tuple<int,int,int>;
const int inf = 2e9+1;
const int mod = 1e9+7;
const int maxn = 1e5+100;
template<typename X, typename Y> bool ckmin(X& x, const Y& y) { return (y < x) ? (x=y,1):0; }
template<typename X, typename Y> bool ckmax(X& x, const Y& y) { return (x < y) ? (x=y,1):0; }
string a,b;
int pref[maxn][3][2], pr[maxn][3][2], n;
map<char,int>t;
ii getType(int i){
if(a[i]=='A'&&b[i]=='C')return {0,0};
if(a[i]=='A'&&b[i]=='T')return {1,0};
if(a[i]=='C'&&b[i]=='T')return {2,0};
if(a[i]=='C'&&b[i]=='A')return {0,1};
if(a[i]=='T'&&b[i]=='A')return {1,1};
if(a[i]=='T'&&b[i]=='C')return {2,1};
return {-1,-1};
}
void init(string s1,string s2){
a = s1, b = s2;
n = sz(a);
t['A'] = 0, t['C'] = 1, t['T'] = 2;
pref[0][t[a[0]]][0] = pref[0][t[b[0]]][1] = 1;
ii cur = getType(0);
if(cur.first!=-1)pr[0][cur.first][cur.second]++;
for(int i=1;i<n;++i){
for(int j=0;j<3;++j)pref[i][j][0] = pref[i-1][j][0], pref[i][j][1] = pref[i-1][j][1];
pref[i][t[a[i]]][0]++, pref[i][t[b[i]]][1]++;
for(int j=0;j<3;++j)pr[i][j][0] = pr[i-1][j][0], pr[i][j][1] = pr[i-1][j][1];
cur = getType(i);
if(cur.first!=-1)pr[i][cur.first][cur.second]++;
}
}
int getqnt(int l,int r,int x,int y){return pref[r][x][y] - (l==0?0:pref[l-1][x][y]);}
int getqnt2(int l,int r,int x,int y){return pr[r][x][y] - (l==0?0:pr[l-1][x][y]);}
int get_distance(int l,int r){
if(!(getqnt(l,r,0,0)==getqnt(l,r,0,1)&&getqnt(l,r,1,0)==getqnt(l,r,1,1)))return -1;
int ac = getqnt2(l,r,0,0), at = getqnt2(l,r,1,0), ct = getqnt2(l,r,2,0),
ca = getqnt2(l,r,0,1), ta = getqnt2(l,r,1,1), tc = getqnt2(l,r,2,1);
int resp = min(ac,ca) + min(at,ta) + min(tc,ct) + 2*(max(ac,ca) - min(ac,ca));
return resp;
}
// int main(){
// int sd,q;cin>>sd>>q;
// string a,b;cin>>a>>b;
// init(a,b);
// while(q--){
// int l,r;cin>>l>>r;
// cout<<get_distance(l,r)<<endl;
// }
// }
# | 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... |