제출 #887672

#제출 시각아이디문제언어결과실행 시간메모리
887672nnhzzzGenetics (BOI18_genetics)C++14
46 / 100
2016 ms68984 KiB

#include<bits/stdc++.h>

using namespace std;

#define REP(i,a,b) for(int i = (a); i<=(b); ++i)
#define REPD(i,a,b) for(int i = (a); i>=(b); --i)
#define REPDIS(i,a,b,c) for(int i = (a); i<=(b); i += c)
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) (int)(x).size()
#define MASK(x) (1LL<<(x))
#define BIT(x,i) (((x)>>(i))&1LL)
#define vi vector<int>
#define vvi vector<vi>
#define vvvi vector<vvi>
#define pii pair<int,int>
#define vpii vector<pii>
#define vvpii vector<vpii>
#define fi first
#define se second
#define gcd __gcd
#define ld long double
#define ll long long
#define ull unsigned long long
#define MP make_pair
#define endl "\n"
//#define int ll

//-------------------------------------------------------------------------------------------------------//
int readInt(){
    char c;
    do{
        c = getchar();
    }while(c!='-' && !isdigit(c));
    bool neg = (c=='-');
    int res = neg?0:c-'0';
    while(isdigit(c=getchar())) res = (res<<3)+(res<<1)+(c-'0');
    return neg?-res:res;
}
//-------------------------------------------------------------------------------------------------------//
template<typename T> bool mini(T &a, const T &b){if(a>b){a=b;return true;}return false;}
template<typename T> bool maxi(T &a, const T &b){if(a<b){a=b;return true;}return false;}
//-------------------------------------------------------------------------------------------------------//
const int MAXN = 4e3+123;
const int MOD = 1e9+7;
const int INF = 1e9;
const int LOG = 16;
const ll LINF = 5e17;
const ld EPS = 1e-9;
const ld PI = acos(-1);
//-------------------------------------------------------------------------------------------------------//

int a[MAXN][MAXN];
int n,m,k;

namespace sub1{

    void solve(){
        REP(l,1,n){
            int ok = 1;
            REP(i,1,n){
                if(i==l) continue;
                int cnt = 0;
                REP(j,1,m) if(a[l][j]!=a[i][j]) ++cnt;
                if(cnt!=k){
                    ok = 0;
                    break;
                }
            }
            if(ok){
                cout << l;
                return ;
            }
        }
    }
}

mt19937 rd(chrono::steady_clock::now().time_since_epoch().count());

namespace sub2{
    bitset<MAXN> f[MAXN];
    int idx[MAXN];

    void solve(){
        srand(time(0));
        REP(i,1,n) idx[i] = i;
        shuffle(idx+1,idx+n+1,rd);
        REP(i,1,n) REP(j,1,m) f[i][j] = a[i][j]-1;
        REP(l,1,n){
            cerr << idx[l];
            int ok = 1;
            REP(i,1,n){
                if(idx[i]==idx[l]) continue;
                if((f[idx[l]]^f[idx[i]]).count()!=k){
                    ok = 0;
                    break;
                }
            }
            if(ok){
                cout << idx[l];
                return ;
            }
        }
    }
}

void solve(){
    cin >> n >> m >> k;
    int s2 = 1;
    REP(i,1,n){
        REP(j,1,m){
            char ch; cin >> ch;
            if(ch=='A') a[i][j] = 1;
            if(ch=='C') a[i][j] = 2;
            if(ch=='G') a[i][j] = 3;
            if(ch=='T') a[i][j] = 4;
            if(a[i][j]>2) s2 = 0;
        }
    }
    if(s2){
        sub2::solve();
        return ;
    }
    sub1::solve();
}

signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    #define task "test"
    if(fopen(task".inp","r")){
        freopen(task".inp","r",stdin);
        freopen(task".out","w",stdout);
    }
    #define task1 "nothing"
    if(fopen(task1".inp","r")){
        freopen(task1".inp","r",stdin);
        freopen(task1".out","w",stdout);
    }
    int test = 1;
    while(test--){
        solve();
        cout << endl;
    }
    return 0;
}

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

genetics.cpp: In function 'void sub2::solve()':
genetics.cpp:94:49: warning: comparison of integer expressions of different signedness: 'std::size_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   94 |                 if((f[idx[l]]^f[idx[i]]).count()!=k){
      |                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
genetics.cpp: In function 'int main()':
genetics.cpp:132:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  132 |         freopen(task".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
genetics.cpp:133:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  133 |         freopen(task".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
genetics.cpp:137:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  137 |         freopen(task1".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
genetics.cpp:138:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  138 |         freopen(task1".out","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...