제출 #707923

#제출 시각아이디문제언어결과실행 시간메모리
707923Alihan_8DNA 돌연변이 (IOI21_dna)C++17
100 / 100
47 ms7652 KiB
#include <bits/stdc++.h>
#include "dna.h"
#define Flag false
// include <ext/pb_ds/assoc_container.hpp>
// include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;
#define all(x) x.begin(), x.end()
#define pb push_back
// define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
#define mpr make_pair
#define ln '\n'
void IO(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
//#define int long long
string l, r;
vector <array<array<int,3>,3>> pref;
map <char,int> id;
int n;
void init(string a, string b) {
    l = a, r = b;
    n = (int)a.size();
    pref.resize(n);
    id['A'] = 0, id['T'] = 1, id['C'] = 2;
    for ( int i = 0; i < n; i++ ){
        for ( int j = 0; j < 3; j++ ){
            for ( int k = 0; k < 3; k++ ){
                if ( i ) pref[i][j][k] = pref[i-1][j][k];
            }
        }
        pref[i][id[l[i]]][id[r[i]]]++;
    }
}
int get(int l, int r, int x, int y){
    int val = pref[r][x][y];
    if ( l ) val -= pref[l-1][x][y];
    return val;
}
int get_distance(int x, int y){
    array <array<int,3>,3> p;
    for ( int i = 0; i < 3; i++ ){
        for ( int j = 0; j < 3; j++ ){
            p[i][j] = get(x, y, i, j);
        }
    }
    auto f = [&](int &a, int &b){
        int Mn = min(a, b);
        a -= Mn, b -= Mn;
        return Mn;
    };
    int cnt = 0;
    for ( int i = 0; i < 3; i++ ){
        for ( int j = i+1; j < 3; j++ ){
            cnt += f(p[i][j], p[j][i]);
        }
    }
    if ( p[0][1] > p[1][2] ) return -1;
    p[0][2] += p[0][1];  p[1][2] -= p[0][1];
    cnt += p[0][1]; p[0][1] = 0;
    if ( p[1][0] > p[2][1] ) return -1;
    p[2][0] += p[1][0];  p[2][1] -= p[1][0];
    cnt += p[1][0]; p[1][0] = 0;
    for ( int i = 0; i < 3; i++ ){
        for ( int j = i+1; j < 3; j++ ){
            if ( p[i][j] != p[j][i] ) return -1;
            cnt += p[i][j];
        }
    }
    return cnt;
}
#if Flag
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int _n, q; cin >> _n >> q;
    string a, b; cin >> a >> b;
    init(a, b);
    while ( q-- ){
        int x, y; cin >> x >> y;
        cout << get_distance(x, y) << ln;
    }

    cout << '\n';
/*
6 3
ATACAT ACTATA
1 3
4 5
3 5
answer: {2, 1, -1}
*/
}
#endif

컴파일 시 표준 에러 (stderr) 메시지

dna.cpp: In function 'void IO(std::string)':
dna.cpp:13:29: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 | void IO(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
      |                      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
dna.cpp:13:70: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 | void IO(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
      |                                                               ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...