제출 #722172

#제출 시각아이디문제언어결과실행 시간메모리
722172Jarif_RahmanGenetics (BOI18_genetics)C++17
19 / 100
2036 ms14732 KiB
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int next(int a, int b){
    return uniform_int_distribution<int>(a, b)(rng);
}

int n, m, k;
bitset<4100> candidate;
char s[4100][4100];
int cnt[4100][4];
int dna[255];

int comp(int a, int b){
    int c = 0;
    for(int i = 0; i < m; i++) if(s[a][i] != s[b][i]) c++;
    return c;
}

int ans = -1;
void dfs(int nd){
    if(ans != -1) return;
    if(!candidate[nd]) return;
    int nxt = -1;
    bool ok = 1;
    for(int i = 0; i < n; i++) if(i != nd && candidate[i]){
        int c = comp(i, nd);
        if(c == k){
            nxt = i;
            if(!ok){
                dfs(i);
                break;
            }
        }
        else{
            ok = 0;
            candidate[nd] = 0;
            candidate[i] = 0;
            if(nxt != -1){
                dfs(nxt);
                break;
            }
        }
    }
    if(!ok) return;
    for(int i = 0; i < n; i++) if(i != nd && !candidate[i]){
        int c = comp(i, nd);
        if(c != k){
            ok = 0;
            break;
        }
    }

    if(ok) ans = nd;
    else candidate[nd] = 0, dfs(nxt);
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    dna['A'] = 0, dna['T'] = 1, dna['C'] = 2, dna['G'] = 3;

    cin >> n >> m >> k;
    candidate.flip();

    for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) cin >> s[i][j];

    for(int T = 0; T  <= 10; T++){
        vector<int> cur;
        vector<bool> in(n, 0);
        for(int i = 0; i < n; i++){
            if(T == 0 || next(0, 1) == 1) in[i] = 1, cur.pb(i);
        }
        if(cur.empty()) cur = {0};
        
        for(int i: cur) for(int j = 0; j < m; j++){
            if(i == cur[0]) cnt[j][0] = 0, cnt[j][1] = 0, cnt[j][2] = 0, cnt[j][3] = 0;
            cnt[j][dna[s[i][j]]]++;
        }

        for(int i = 0; i < n; i++){
            int c = 0;
            for(int j = 0; j < m; j++) for(int x = 0; x < 4; x++) if(x != dna[s[i][j]]) c+=cnt[j][x];
            if(c != k*cur.size()-k*in[i]) candidate[i] = 0;
        }
    }

    for(int i = 0; i < n; i++) if(candidate[i]){
        dfs(i);
        break;
    }

    cout << ans+1 << "\n";
}

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

genetics.cpp: In function 'int main()':
genetics.cpp:85:30: warning: array subscript has type 'char' [-Wchar-subscripts]
   85 |             cnt[j][dna[s[i][j]]]++;
      |                        ~~~~~~^
genetics.cpp:90:85: warning: array subscript has type 'char' [-Wchar-subscripts]
   90 |             for(int j = 0; j < m; j++) for(int x = 0; x < 4; x++) if(x != dna[s[i][j]]) c+=cnt[j][x];
      |                                                                               ~~~~~~^
genetics.cpp:91:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   91 |             if(c != k*cur.size()-k*in[i]) candidate[i] = 0;
      |                ~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...