답안 #62715

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
62715 2018-07-29T21:39:48 Z eriksuenderhauf Genetics (BOI18_genetics) C++11
100 / 100
1453 ms 70904 KB
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define enl printf("\n")
#define case(t) printf("Case #%d: ", (t))
#define ni(n) scanf("%d", &(n))
#define nl(n) scanf("%I64d", &(n))
#define nai(a, n) for (int i = 0; i < (n); i++) ni(a[i])
#define nal(a, n) for (int i = 0; i < (n); i++) nl(a[i])
#define pri(n) printf("%d\n", (n))
#define prl(n) printf("%I64d\n", (n))
#define pii pair<int, int>
#define vii vector<pii>
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
const double pi = acos(-1);
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const int MAXN = 5e3 + 5;
const double eps = 1e-9;
using namespace std;
char str[MAXN][MAXN];
bitset<MAXN> a[MAXN][4];
int cnt[MAXN][4];
short vis[MAXN][MAXN];

int go(char c)
{
    if (c == 'A') return 0;
    else if (c == 'C') return 1;
    else if (c == 'G') return 2;
    else if (c == 'T') return 3;
}

int main()
{
    int n, m, k;
    ni(n), ni(m), ni(k);
    for (int i = 0; i < n; i++)
    {
        scanf("%s", str[i]);
        for (int j = 0; j < m; j++)
        {
            int cur = go(str[i][j]);
            a[i][cur][j] = 1;
            cnt[j][cur]++;
            vis[i][j] = -1;
        }
        for (int j = m; j < n; j++)
            vis[i][j] = -1;
    }
    for (short i = n - 2; i >= 0; i -= 2)
    {
        int tmp = 0;
        for (short j = 0; j < m; j++)
            tmp += n - cnt[j][go(str[i][j])];
        if (tmp != k * (n - 1))
            continue;
        bool fl = 0;
        for (short j = n - 1; j >= 0; j--)
        {
            if (i == j)
                continue;
            short val = 0;
            if (vis[i][j] != -1)
                val = vis[i][j];
            else
            {
                for (short b = 0; b < 4; b++)
                {
                    val += (a[i][b] ^ a[j][b]).count();
                    if (val > 2 * k)
                        break;
                }
                vis[i][j] = val;
                vis[j][i] = val;
            }
            if (val != 2 * k)
            {
                fl = 1;
                break;
            }
        }
        if (fl)
            continue;
        return !pri(i + 1);
    }

    for (short i = n - 1; i >= 0; i -= 2)
    {
        int tmp = 0;
        for (short j = 0; j < m; j++)
            tmp += n - cnt[j][go(str[i][j])];
        if (tmp != k * (n - 1))
            continue;
        bool fl = 0;
        for (short j = n - 1; j >= 0; j--)
        {
            if (i == j)
                continue;
            short val = 0;
            if (vis[i][j] != -1)
                val = vis[i][j];
            else
            {
                for (short b = 0; b < 4; b++)
                {
                    val += (a[i][b] ^ a[j][b]).count();
                    if (val > 2 * k)
                        break;
                }
                vis[i][j] = val;
                vis[j][i] = val;
            }
            if (val != 2 * k)
            {
                fl = 1;
                break;
            }
        }
        if (fl)
            continue;
        return !pri(i + 1);
    }
    return 0;
}

Compilation message

genetics.cpp: In function 'int go(char)':
genetics.cpp:36:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
genetics.cpp: In function 'int main()':
genetics.cpp:41:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     ni(n), ni(m), ni(k);
                 ^
genetics.cpp:41:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
genetics.cpp:41:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
genetics.cpp:44:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%s", str[i]);
         ~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 1272 KB Output is correct
2 Correct 5 ms 1400 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 1144 KB Output is correct
5 Correct 5 ms 1272 KB Output is correct
6 Correct 5 ms 1272 KB Output is correct
7 Correct 5 ms 888 KB Output is correct
8 Correct 4 ms 376 KB Output is correct
9 Correct 5 ms 1016 KB Output is correct
10 Correct 6 ms 1400 KB Output is correct
11 Correct 5 ms 1144 KB Output is correct
12 Correct 5 ms 1400 KB Output is correct
13 Correct 5 ms 1404 KB Output is correct
14 Correct 6 ms 1400 KB Output is correct
15 Correct 6 ms 1400 KB Output is correct
16 Correct 5 ms 1400 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 48 ms 22776 KB Output is correct
2 Correct 52 ms 27256 KB Output is correct
3 Correct 54 ms 25976 KB Output is correct
4 Correct 24 ms 15608 KB Output is correct
5 Correct 64 ms 27128 KB Output is correct
6 Correct 61 ms 27128 KB Output is correct
7 Correct 27 ms 11768 KB Output is correct
8 Correct 26 ms 11896 KB Output is correct
9 Correct 250 ms 25848 KB Output is correct
10 Correct 64 ms 25848 KB Output is correct
11 Correct 346 ms 22776 KB Output is correct
12 Correct 211 ms 22776 KB Output is correct
13 Correct 116 ms 22648 KB Output is correct
14 Correct 42 ms 19448 KB Output is correct
15 Correct 78 ms 19704 KB Output is correct
16 Correct 54 ms 21496 KB Output is correct
17 Correct 56 ms 25976 KB Output is correct
18 Correct 72 ms 25852 KB Output is correct
19 Correct 56 ms 26104 KB Output is correct
20 Correct 71 ms 25732 KB Output is correct
21 Correct 68 ms 26104 KB Output is correct
22 Correct 54 ms 25720 KB Output is correct
23 Correct 63 ms 25976 KB Output is correct
24 Correct 54 ms 25852 KB Output is correct
25 Correct 60 ms 25720 KB Output is correct
26 Correct 58 ms 25976 KB Output is correct
27 Correct 69 ms 25848 KB Output is correct
28 Correct 68 ms 25720 KB Output is correct
29 Correct 66 ms 25852 KB Output is correct
30 Correct 53 ms 27128 KB Output is correct
31 Correct 49 ms 27132 KB Output is correct
32 Correct 63 ms 27128 KB Output is correct
33 Correct 5 ms 504 KB Output is correct
34 Correct 5 ms 1400 KB Output is correct
35 Correct 5 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 48 ms 22776 KB Output is correct
2 Correct 52 ms 27256 KB Output is correct
3 Correct 54 ms 25976 KB Output is correct
4 Correct 24 ms 15608 KB Output is correct
5 Correct 64 ms 27128 KB Output is correct
6 Correct 61 ms 27128 KB Output is correct
7 Correct 27 ms 11768 KB Output is correct
8 Correct 26 ms 11896 KB Output is correct
9 Correct 250 ms 25848 KB Output is correct
10 Correct 64 ms 25848 KB Output is correct
11 Correct 346 ms 22776 KB Output is correct
12 Correct 211 ms 22776 KB Output is correct
13 Correct 116 ms 22648 KB Output is correct
14 Correct 42 ms 19448 KB Output is correct
15 Correct 78 ms 19704 KB Output is correct
16 Correct 54 ms 21496 KB Output is correct
17 Correct 56 ms 25976 KB Output is correct
18 Correct 72 ms 25852 KB Output is correct
19 Correct 56 ms 26104 KB Output is correct
20 Correct 71 ms 25732 KB Output is correct
21 Correct 68 ms 26104 KB Output is correct
22 Correct 54 ms 25720 KB Output is correct
23 Correct 63 ms 25976 KB Output is correct
24 Correct 54 ms 25852 KB Output is correct
25 Correct 60 ms 25720 KB Output is correct
26 Correct 58 ms 25976 KB Output is correct
27 Correct 69 ms 25848 KB Output is correct
28 Correct 68 ms 25720 KB Output is correct
29 Correct 66 ms 25852 KB Output is correct
30 Correct 53 ms 27128 KB Output is correct
31 Correct 49 ms 27132 KB Output is correct
32 Correct 63 ms 27128 KB Output is correct
33 Correct 5 ms 504 KB Output is correct
34 Correct 5 ms 1400 KB Output is correct
35 Correct 5 ms 376 KB Output is correct
36 Correct 352 ms 61948 KB Output is correct
37 Correct 221 ms 70904 KB Output is correct
38 Correct 224 ms 69240 KB Output is correct
39 Correct 112 ms 59640 KB Output is correct
40 Correct 256 ms 70648 KB Output is correct
41 Correct 126 ms 35576 KB Output is correct
42 Correct 155 ms 35576 KB Output is correct
43 Correct 407 ms 59760 KB Output is correct
44 Correct 748 ms 70648 KB Output is correct
45 Correct 359 ms 70904 KB Output is correct
46 Correct 507 ms 70648 KB Output is correct
47 Correct 650 ms 62072 KB Output is correct
48 Correct 1453 ms 61944 KB Output is correct
49 Correct 947 ms 53240 KB Output is correct
50 Correct 182 ms 53112 KB Output is correct
51 Correct 255 ms 59768 KB Output is correct
52 Correct 287 ms 68984 KB Output is correct
53 Correct 287 ms 68984 KB Output is correct
54 Correct 239 ms 69112 KB Output is correct
55 Correct 219 ms 69076 KB Output is correct
56 Correct 266 ms 68984 KB Output is correct
57 Correct 277 ms 69112 KB Output is correct
58 Correct 249 ms 69112 KB Output is correct
59 Correct 316 ms 68856 KB Output is correct
60 Correct 265 ms 69240 KB Output is correct
61 Correct 262 ms 68856 KB Output is correct
62 Correct 265 ms 68680 KB Output is correct
63 Correct 289 ms 69112 KB Output is correct
64 Correct 268 ms 69240 KB Output is correct
65 Correct 285 ms 68860 KB Output is correct
66 Correct 292 ms 69112 KB Output is correct
67 Correct 244 ms 69192 KB Output is correct
68 Correct 253 ms 69112 KB Output is correct
69 Correct 268 ms 68984 KB Output is correct
70 Correct 241 ms 69084 KB Output is correct
71 Correct 306 ms 68856 KB Output is correct
72 Correct 307 ms 69568 KB Output is correct
73 Correct 242 ms 68840 KB Output is correct
74 Correct 5 ms 376 KB Output is correct
75 Correct 6 ms 1404 KB Output is correct
76 Correct 5 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 1272 KB Output is correct
2 Correct 5 ms 1400 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 1144 KB Output is correct
5 Correct 5 ms 1272 KB Output is correct
6 Correct 5 ms 1272 KB Output is correct
7 Correct 5 ms 888 KB Output is correct
8 Correct 4 ms 376 KB Output is correct
9 Correct 5 ms 1016 KB Output is correct
10 Correct 6 ms 1400 KB Output is correct
11 Correct 5 ms 1144 KB Output is correct
12 Correct 5 ms 1400 KB Output is correct
13 Correct 5 ms 1404 KB Output is correct
14 Correct 6 ms 1400 KB Output is correct
15 Correct 6 ms 1400 KB Output is correct
16 Correct 5 ms 1400 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 48 ms 22776 KB Output is correct
19 Correct 52 ms 27256 KB Output is correct
20 Correct 54 ms 25976 KB Output is correct
21 Correct 24 ms 15608 KB Output is correct
22 Correct 64 ms 27128 KB Output is correct
23 Correct 61 ms 27128 KB Output is correct
24 Correct 27 ms 11768 KB Output is correct
25 Correct 26 ms 11896 KB Output is correct
26 Correct 250 ms 25848 KB Output is correct
27 Correct 64 ms 25848 KB Output is correct
28 Correct 346 ms 22776 KB Output is correct
29 Correct 211 ms 22776 KB Output is correct
30 Correct 116 ms 22648 KB Output is correct
31 Correct 42 ms 19448 KB Output is correct
32 Correct 78 ms 19704 KB Output is correct
33 Correct 54 ms 21496 KB Output is correct
34 Correct 56 ms 25976 KB Output is correct
35 Correct 72 ms 25852 KB Output is correct
36 Correct 56 ms 26104 KB Output is correct
37 Correct 71 ms 25732 KB Output is correct
38 Correct 68 ms 26104 KB Output is correct
39 Correct 54 ms 25720 KB Output is correct
40 Correct 63 ms 25976 KB Output is correct
41 Correct 54 ms 25852 KB Output is correct
42 Correct 60 ms 25720 KB Output is correct
43 Correct 58 ms 25976 KB Output is correct
44 Correct 69 ms 25848 KB Output is correct
45 Correct 68 ms 25720 KB Output is correct
46 Correct 66 ms 25852 KB Output is correct
47 Correct 53 ms 27128 KB Output is correct
48 Correct 49 ms 27132 KB Output is correct
49 Correct 63 ms 27128 KB Output is correct
50 Correct 5 ms 504 KB Output is correct
51 Correct 5 ms 1400 KB Output is correct
52 Correct 5 ms 376 KB Output is correct
53 Correct 352 ms 61948 KB Output is correct
54 Correct 221 ms 70904 KB Output is correct
55 Correct 224 ms 69240 KB Output is correct
56 Correct 112 ms 59640 KB Output is correct
57 Correct 256 ms 70648 KB Output is correct
58 Correct 126 ms 35576 KB Output is correct
59 Correct 155 ms 35576 KB Output is correct
60 Correct 407 ms 59760 KB Output is correct
61 Correct 748 ms 70648 KB Output is correct
62 Correct 359 ms 70904 KB Output is correct
63 Correct 507 ms 70648 KB Output is correct
64 Correct 650 ms 62072 KB Output is correct
65 Correct 1453 ms 61944 KB Output is correct
66 Correct 947 ms 53240 KB Output is correct
67 Correct 182 ms 53112 KB Output is correct
68 Correct 255 ms 59768 KB Output is correct
69 Correct 287 ms 68984 KB Output is correct
70 Correct 287 ms 68984 KB Output is correct
71 Correct 239 ms 69112 KB Output is correct
72 Correct 219 ms 69076 KB Output is correct
73 Correct 266 ms 68984 KB Output is correct
74 Correct 277 ms 69112 KB Output is correct
75 Correct 249 ms 69112 KB Output is correct
76 Correct 316 ms 68856 KB Output is correct
77 Correct 265 ms 69240 KB Output is correct
78 Correct 262 ms 68856 KB Output is correct
79 Correct 265 ms 68680 KB Output is correct
80 Correct 289 ms 69112 KB Output is correct
81 Correct 268 ms 69240 KB Output is correct
82 Correct 285 ms 68860 KB Output is correct
83 Correct 292 ms 69112 KB Output is correct
84 Correct 244 ms 69192 KB Output is correct
85 Correct 253 ms 69112 KB Output is correct
86 Correct 268 ms 68984 KB Output is correct
87 Correct 241 ms 69084 KB Output is correct
88 Correct 306 ms 68856 KB Output is correct
89 Correct 307 ms 69568 KB Output is correct
90 Correct 242 ms 68840 KB Output is correct
91 Correct 5 ms 376 KB Output is correct
92 Correct 6 ms 1404 KB Output is correct
93 Correct 5 ms 504 KB Output is correct
94 Correct 342 ms 67200 KB Output is correct
95 Correct 221 ms 70776 KB Output is correct
96 Correct 270 ms 69612 KB Output is correct
97 Correct 146 ms 37996 KB Output is correct
98 Correct 153 ms 59640 KB Output is correct
99 Correct 302 ms 70852 KB Output is correct
100 Correct 152 ms 35576 KB Output is correct
101 Correct 159 ms 35576 KB Output is correct
102 Correct 349 ms 60024 KB Output is correct
103 Correct 423 ms 70776 KB Output is correct
104 Correct 427 ms 70856 KB Output is correct
105 Correct 274 ms 70652 KB Output is correct
106 Correct 520 ms 67320 KB Output is correct
107 Correct 806 ms 62072 KB Output is correct
108 Correct 300 ms 53112 KB Output is correct
109 Correct 452 ms 61176 KB Output is correct
110 Correct 290 ms 59768 KB Output is correct
111 Correct 325 ms 70776 KB Output is correct
112 Correct 372 ms 69880 KB Output is correct
113 Correct 239 ms 69112 KB Output is correct
114 Correct 214 ms 69240 KB Output is correct
115 Correct 274 ms 69112 KB Output is correct
116 Correct 371 ms 69880 KB Output is correct
117 Correct 287 ms 69880 KB Output is correct
118 Correct 371 ms 70028 KB Output is correct
119 Correct 308 ms 69628 KB Output is correct
120 Correct 288 ms 69880 KB Output is correct
121 Correct 347 ms 62072 KB Output is correct
122 Correct 212 ms 70776 KB Output is correct
123 Correct 229 ms 69112 KB Output is correct
124 Correct 5 ms 376 KB Output is correct
125 Correct 5 ms 1400 KB Output is correct
126 Correct 5 ms 504 KB Output is correct