답안 #117489

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
117489 2019-06-16T08:48:00 Z ckodser Genetics (BOI18_genetics) C++14
46 / 100
2000 ms 29152 KB
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

int gcd(int a, int b) {return b == 0 ? a : gcd(b, a % b);}

#define ll int
#define pb push_back
#define ld long double
#define mp make_pair
#define F first
#define S second
#define pii pair<ll,ll> 

using namespace :: std;

const ll maxn=4110;
const ll maxg=100;

ll mxx=1;

string s[maxn];
bitset<maxn> bi[maxn][4];

bool hast[maxg][maxn];
ll sz[maxg];
ll cnt[maxg][maxn][4];

ll n,m,k,rk;

bitset<maxn> vis[maxn];
bitset<maxn> ASS[maxn];



bool canBeAns(ll i){
	for(ll y=0;y<maxg;y++){
		ll ans=0;
		ll szz=sz[y];
		for(ll j=0;j<m;j++){
			ans+=cnt[y][j][s[i][j]];
		}
		if(hast[y][i]){
			ans-=m;
			szz--;
		}
		if(ans!=szz*(m-rk)){
			return 0;
		}
	}
	return 1;
}
ll dif(ll i,ll j){
	ll ans=0;
	for(ll y=0;y<mxx;y++){
		ans+=(bi[i][y]^bi[j][y]).count();
	}
	return ans;
}
bool is_good(ll i,ll j){
	if(vis[i][j])return ASS[i][j];
	bool b=(dif(i,j)==k);
	vis[i][j]=1;
	vis[j][i]=1;
	ASS[i][j]=b;
	ASS[j][i]=b;
	return b;
}
bool isAns(ll a){
	for(ll i=0;i<n;i++){
		if(i!=a){
			if(!is_good(i,a)){
				return 0;
			}
		}
	}
	return 1;
}

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);	
	cin>>n>>m>>k;
	rk=k;
	if(n<=100 && m<=100){
		k*=2;
		mxx=4;
	}
	for(ll i=0;i<n;i++){
		cin>>s[i];
	}
	for(ll i=0;i<n;i++){
		for(ll j=0;j<m;j++){
			if(s[i][j]=='A')s[i][j]=0;
			if(s[i][j]=='C')s[i][j]=1;
			if(s[i][j]=='T')s[i][j]=2;
			if(s[i][j]=='G')s[i][j]=3;
			bi[i][s[i][j]][j]=1;
		}
		for(ll y=0;y<maxg;y++){
			if(rand()%2==0){
				hast[y][i]=1;
				sz[y]++;
				for(ll j=0;j<m;j++){
					cnt[y][j][s[i][j]]++;
				}
			}
		}	
	}
	set<ll> st;
	for(ll i=0;i<n;i++){
		if(canBeAns(i)){
			bool b=0;
			for(auto e:st){
				if(!is_good(e,i)){
					st.erase(e);
					b=1;
					break;
				}
			}	
			if(!b){
				st.insert(i);
			}
			if(st.size()>7){
				exit(1);
			}
		}
	}
	for(auto e:st){
		if(isAns(e)){
			cout<<e+1;
			return 0;
		}
	}

}


















Compilation message

genetics.cpp: In function 'bool canBeAns(int)':
genetics.cpp:91:26: warning: array subscript has type 'char' [-Wchar-subscripts]
    ans+=cnt[y][j][s[i][j]];
                          ^
genetics.cpp: In function 'int main()':
genetics.cpp:147:17: warning: array subscript has type 'char' [-Wchar-subscripts]
    bi[i][s[i][j]][j]=1;
                 ^
genetics.cpp:154:23: warning: array subscript has type 'char' [-Wchar-subscripts]
      cnt[y][j][s[i][j]]++;
                       ^
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 1656 KB Output is correct
2 Correct 8 ms 1784 KB Output is correct
3 Correct 5 ms 1272 KB Output is correct
4 Correct 7 ms 1784 KB Output is correct
5 Correct 7 ms 1656 KB Output is correct
6 Correct 8 ms 1784 KB Output is correct
7 Correct 6 ms 1656 KB Output is correct
8 Correct 5 ms 1272 KB Output is correct
9 Correct 7 ms 1656 KB Output is correct
10 Correct 8 ms 1784 KB Output is correct
11 Correct 8 ms 1656 KB Output is correct
12 Correct 8 ms 1784 KB Output is correct
13 Correct 8 ms 1784 KB Output is correct
14 Correct 8 ms 1784 KB Output is correct
15 Correct 8 ms 1784 KB Output is correct
16 Correct 6 ms 1656 KB Output is correct
17 Correct 5 ms 1528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 572 ms 11384 KB Output is correct
2 Correct 704 ms 13048 KB Output is correct
3 Correct 673 ms 12536 KB Output is correct
4 Correct 153 ms 6392 KB Output is correct
5 Correct 685 ms 13048 KB Output is correct
6 Correct 685 ms 13048 KB Output is correct
7 Correct 304 ms 8056 KB Output is correct
8 Correct 309 ms 7928 KB Output is correct
9 Correct 654 ms 12536 KB Output is correct
10 Correct 653 ms 12408 KB Output is correct
11 Correct 578 ms 11492 KB Output is correct
12 Correct 577 ms 11332 KB Output is correct
13 Correct 575 ms 11512 KB Output is correct
14 Correct 471 ms 10360 KB Output is correct
15 Correct 499 ms 10436 KB Output is correct
16 Correct 500 ms 10488 KB Output is correct
17 Correct 677 ms 12792 KB Output is correct
18 Correct 668 ms 12536 KB Output is correct
19 Correct 699 ms 12736 KB Output is correct
20 Correct 668 ms 12600 KB Output is correct
21 Correct 672 ms 12664 KB Output is correct
22 Correct 672 ms 12536 KB Output is correct
23 Correct 683 ms 12664 KB Output is correct
24 Correct 695 ms 12664 KB Output is correct
25 Correct 694 ms 12664 KB Output is correct
26 Correct 692 ms 12536 KB Output is correct
27 Correct 679 ms 12792 KB Output is correct
28 Correct 673 ms 12536 KB Output is correct
29 Correct 662 ms 12596 KB Output is correct
30 Correct 703 ms 13332 KB Output is correct
31 Correct 708 ms 13048 KB Output is correct
32 Correct 715 ms 12972 KB Output is correct
33 Correct 5 ms 1272 KB Output is correct
34 Correct 7 ms 1784 KB Output is correct
35 Correct 5 ms 1528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 572 ms 11384 KB Output is correct
2 Correct 704 ms 13048 KB Output is correct
3 Correct 673 ms 12536 KB Output is correct
4 Correct 153 ms 6392 KB Output is correct
5 Correct 685 ms 13048 KB Output is correct
6 Correct 685 ms 13048 KB Output is correct
7 Correct 304 ms 8056 KB Output is correct
8 Correct 309 ms 7928 KB Output is correct
9 Correct 654 ms 12536 KB Output is correct
10 Correct 653 ms 12408 KB Output is correct
11 Correct 578 ms 11492 KB Output is correct
12 Correct 577 ms 11332 KB Output is correct
13 Correct 575 ms 11512 KB Output is correct
14 Correct 471 ms 10360 KB Output is correct
15 Correct 499 ms 10436 KB Output is correct
16 Correct 500 ms 10488 KB Output is correct
17 Correct 677 ms 12792 KB Output is correct
18 Correct 668 ms 12536 KB Output is correct
19 Correct 699 ms 12736 KB Output is correct
20 Correct 668 ms 12600 KB Output is correct
21 Correct 672 ms 12664 KB Output is correct
22 Correct 672 ms 12536 KB Output is correct
23 Correct 683 ms 12664 KB Output is correct
24 Correct 695 ms 12664 KB Output is correct
25 Correct 694 ms 12664 KB Output is correct
26 Correct 692 ms 12536 KB Output is correct
27 Correct 679 ms 12792 KB Output is correct
28 Correct 673 ms 12536 KB Output is correct
29 Correct 662 ms 12596 KB Output is correct
30 Correct 703 ms 13332 KB Output is correct
31 Correct 708 ms 13048 KB Output is correct
32 Correct 715 ms 12972 KB Output is correct
33 Correct 5 ms 1272 KB Output is correct
34 Correct 7 ms 1784 KB Output is correct
35 Correct 5 ms 1528 KB Output is correct
36 Execution timed out 2079 ms 29152 KB Time limit exceeded
37 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 1656 KB Output is correct
2 Correct 8 ms 1784 KB Output is correct
3 Correct 5 ms 1272 KB Output is correct
4 Correct 7 ms 1784 KB Output is correct
5 Correct 7 ms 1656 KB Output is correct
6 Correct 8 ms 1784 KB Output is correct
7 Correct 6 ms 1656 KB Output is correct
8 Correct 5 ms 1272 KB Output is correct
9 Correct 7 ms 1656 KB Output is correct
10 Correct 8 ms 1784 KB Output is correct
11 Correct 8 ms 1656 KB Output is correct
12 Correct 8 ms 1784 KB Output is correct
13 Correct 8 ms 1784 KB Output is correct
14 Correct 8 ms 1784 KB Output is correct
15 Correct 8 ms 1784 KB Output is correct
16 Correct 6 ms 1656 KB Output is correct
17 Correct 5 ms 1528 KB Output is correct
18 Correct 572 ms 11384 KB Output is correct
19 Correct 704 ms 13048 KB Output is correct
20 Correct 673 ms 12536 KB Output is correct
21 Correct 153 ms 6392 KB Output is correct
22 Correct 685 ms 13048 KB Output is correct
23 Correct 685 ms 13048 KB Output is correct
24 Correct 304 ms 8056 KB Output is correct
25 Correct 309 ms 7928 KB Output is correct
26 Correct 654 ms 12536 KB Output is correct
27 Correct 653 ms 12408 KB Output is correct
28 Correct 578 ms 11492 KB Output is correct
29 Correct 577 ms 11332 KB Output is correct
30 Correct 575 ms 11512 KB Output is correct
31 Correct 471 ms 10360 KB Output is correct
32 Correct 499 ms 10436 KB Output is correct
33 Correct 500 ms 10488 KB Output is correct
34 Correct 677 ms 12792 KB Output is correct
35 Correct 668 ms 12536 KB Output is correct
36 Correct 699 ms 12736 KB Output is correct
37 Correct 668 ms 12600 KB Output is correct
38 Correct 672 ms 12664 KB Output is correct
39 Correct 672 ms 12536 KB Output is correct
40 Correct 683 ms 12664 KB Output is correct
41 Correct 695 ms 12664 KB Output is correct
42 Correct 694 ms 12664 KB Output is correct
43 Correct 692 ms 12536 KB Output is correct
44 Correct 679 ms 12792 KB Output is correct
45 Correct 673 ms 12536 KB Output is correct
46 Correct 662 ms 12596 KB Output is correct
47 Correct 703 ms 13332 KB Output is correct
48 Correct 708 ms 13048 KB Output is correct
49 Correct 715 ms 12972 KB Output is correct
50 Correct 5 ms 1272 KB Output is correct
51 Correct 7 ms 1784 KB Output is correct
52 Correct 5 ms 1528 KB Output is correct
53 Execution timed out 2079 ms 29152 KB Time limit exceeded
54 Halted 0 ms 0 KB -