Submission #95836

# Submission time Handle Problem Language Result Execution time Memory
95836 2019-02-02T19:58:13 Z caesar2001 Genetics (BOI18_genetics) C++14
46 / 100
2000 ms 693624 KB
#include <bits/stdc++.h>
#define ll long long
#define lsb(x) (x & -x)

using namespace std;

struct Data {
    int from, to, cost;
};

void transpune(const vector<vector<ll>> &v, vector<vector<ll>> &ans, int n, int m) {
    for(int i = 1; i <= n; i ++)
        for(int j = 1; j <= m; j ++)
            ans[j][i] = v[i][j];
}

void multiply(const vector<vector<ll>> &a, const vector<vector<ll>> &b, vector<vector<ll>> &ans, int n, int m, int p) {
    for(int i = 1; i <= n; i ++)
        for(int j = 1; j <= p; j ++)
            for(int k = 1; k <= m; k ++)
                ans[i][j] += (a[i][k] * b[k][j]);
}

void add(vector<vector<ll>> &ans, const vector<vector<ll>> &a, int n, int m) {
    for(int i = 1; i <= n; i ++)
        for(int j = 1; j <= m; j ++)
            ans[i][j] += a[i][j];
}

int main() {
    //ios::sync_with_stdio(false);
    //cin.tie(0);
    //cout.tie(0);
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);

    int n, m, k;
    cin >> n >> m >> k;
    k = m - k;

    vector<int> code(30, 0);
    code['A' - 'A'] = 1;
    code['C' - 'A'] = 2;
    code['G' - 'A'] = 3;
    code['T' - 'A'] = 4;

    vector<vector<vector<ll>>> v(5, vector<vector<ll>> (n + 1, vector<ll> (m + 1, 0)));
    for(int i = 1; i <= n; i ++) {
        string s;
        cin >> s;

        for(int j = 0; j < m; j ++)
            v[code[s[j] - 'A']][i][j + 1] = 1;
    }

    srand(time(NULL));

    vector<vector<ll>> hs(n + 1, vector<ll> (2, 0));
    for(int i = 1; i <= n; i ++)
        hs[i][1] = rand();

    vector<vector<ll>> ans(n + 1, vector<ll> (2, 0));
    for(int i = 1; i <= 4; i ++) {
        vector<vector<ll>> t(m + 1, vector<ll> (n + 1, 0));
        transpune(v[i], t, n, m);

        vector<vector<ll>> ths(m + 1, vector<ll> (2, 0));
        multiply(t, hs, ths, m, n, 1);

        vector<vector<ll>> aux(n + 1, vector<ll> (2, 0));
        multiply(v[i], ths, aux, n, m, 1);
        add(ans, aux, n, 1);
    }

    vector<vector<ll>> sol(n + 1, vector<ll> (n + 1, k));
    for(int i = 1; i <= n; i ++)
        sol[i][i] = m;
    vector<vector<ll>> solhs(n + 1, vector<ll> (2, 0));
    multiply(sol, hs, solhs, n, n, 1);

    for(int i = 1; i <= n; i ++) {
        if(solhs[i][1] == ans[i][1]) {
            cout << i;
            return 0;
        }
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 760 KB Output is correct
2 Correct 6 ms 760 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 5 ms 632 KB Output is correct
5 Correct 5 ms 632 KB Output is correct
6 Correct 6 ms 760 KB Output is correct
7 Correct 5 ms 504 KB Output is correct
8 Correct 5 ms 256 KB Output is correct
9 Correct 5 ms 508 KB Output is correct
10 Correct 6 ms 760 KB Output is correct
11 Correct 5 ms 760 KB Output is correct
12 Correct 6 ms 760 KB Output is correct
13 Correct 6 ms 760 KB Output is correct
14 Correct 6 ms 760 KB Output is correct
15 Correct 6 ms 888 KB Output is correct
16 Correct 5 ms 504 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 428 ms 123932 KB Output is correct
2 Correct 526 ms 153512 KB Output is correct
3 Correct 498 ms 146460 KB Output is correct
4 Correct 91 ms 37208 KB Output is correct
5 Correct 517 ms 153464 KB Output is correct
6 Correct 524 ms 153464 KB Output is correct
7 Correct 216 ms 65656 KB Output is correct
8 Correct 222 ms 65784 KB Output is correct
9 Correct 471 ms 141492 KB Output is correct
10 Correct 479 ms 141636 KB Output is correct
11 Correct 420 ms 123968 KB Output is correct
12 Correct 420 ms 124716 KB Output is correct
13 Correct 417 ms 123932 KB Output is correct
14 Correct 357 ms 106348 KB Output is correct
15 Correct 368 ms 107640 KB Output is correct
16 Correct 347 ms 107184 KB Output is correct
17 Correct 491 ms 146808 KB Output is correct
18 Correct 497 ms 145784 KB Output is correct
19 Correct 502 ms 147116 KB Output is correct
20 Correct 506 ms 144928 KB Output is correct
21 Correct 498 ms 146680 KB Output is correct
22 Correct 495 ms 145284 KB Output is correct
23 Correct 493 ms 146184 KB Output is correct
24 Correct 497 ms 146328 KB Output is correct
25 Correct 497 ms 145004 KB Output is correct
26 Correct 503 ms 146424 KB Output is correct
27 Correct 500 ms 145332 KB Output is correct
28 Correct 499 ms 145144 KB Output is correct
29 Correct 504 ms 146216 KB Output is correct
30 Correct 514 ms 153348 KB Output is correct
31 Correct 513 ms 153396 KB Output is correct
32 Correct 525 ms 153336 KB Output is correct
33 Correct 5 ms 256 KB Output is correct
34 Correct 6 ms 760 KB Output is correct
35 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 428 ms 123932 KB Output is correct
2 Correct 526 ms 153512 KB Output is correct
3 Correct 498 ms 146460 KB Output is correct
4 Correct 91 ms 37208 KB Output is correct
5 Correct 517 ms 153464 KB Output is correct
6 Correct 524 ms 153464 KB Output is correct
7 Correct 216 ms 65656 KB Output is correct
8 Correct 222 ms 65784 KB Output is correct
9 Correct 471 ms 141492 KB Output is correct
10 Correct 479 ms 141636 KB Output is correct
11 Correct 420 ms 123968 KB Output is correct
12 Correct 420 ms 124716 KB Output is correct
13 Correct 417 ms 123932 KB Output is correct
14 Correct 357 ms 106348 KB Output is correct
15 Correct 368 ms 107640 KB Output is correct
16 Correct 347 ms 107184 KB Output is correct
17 Correct 491 ms 146808 KB Output is correct
18 Correct 497 ms 145784 KB Output is correct
19 Correct 502 ms 147116 KB Output is correct
20 Correct 506 ms 144928 KB Output is correct
21 Correct 498 ms 146680 KB Output is correct
22 Correct 495 ms 145284 KB Output is correct
23 Correct 493 ms 146184 KB Output is correct
24 Correct 497 ms 146328 KB Output is correct
25 Correct 497 ms 145004 KB Output is correct
26 Correct 503 ms 146424 KB Output is correct
27 Correct 500 ms 145332 KB Output is correct
28 Correct 499 ms 145144 KB Output is correct
29 Correct 504 ms 146216 KB Output is correct
30 Correct 514 ms 153348 KB Output is correct
31 Correct 513 ms 153396 KB Output is correct
32 Correct 525 ms 153336 KB Output is correct
33 Correct 5 ms 256 KB Output is correct
34 Correct 6 ms 760 KB Output is correct
35 Correct 5 ms 376 KB Output is correct
36 Execution timed out 2117 ms 693624 KB Time limit exceeded
37 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 760 KB Output is correct
2 Correct 6 ms 760 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 5 ms 632 KB Output is correct
5 Correct 5 ms 632 KB Output is correct
6 Correct 6 ms 760 KB Output is correct
7 Correct 5 ms 504 KB Output is correct
8 Correct 5 ms 256 KB Output is correct
9 Correct 5 ms 508 KB Output is correct
10 Correct 6 ms 760 KB Output is correct
11 Correct 5 ms 760 KB Output is correct
12 Correct 6 ms 760 KB Output is correct
13 Correct 6 ms 760 KB Output is correct
14 Correct 6 ms 760 KB Output is correct
15 Correct 6 ms 888 KB Output is correct
16 Correct 5 ms 504 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 428 ms 123932 KB Output is correct
19 Correct 526 ms 153512 KB Output is correct
20 Correct 498 ms 146460 KB Output is correct
21 Correct 91 ms 37208 KB Output is correct
22 Correct 517 ms 153464 KB Output is correct
23 Correct 524 ms 153464 KB Output is correct
24 Correct 216 ms 65656 KB Output is correct
25 Correct 222 ms 65784 KB Output is correct
26 Correct 471 ms 141492 KB Output is correct
27 Correct 479 ms 141636 KB Output is correct
28 Correct 420 ms 123968 KB Output is correct
29 Correct 420 ms 124716 KB Output is correct
30 Correct 417 ms 123932 KB Output is correct
31 Correct 357 ms 106348 KB Output is correct
32 Correct 368 ms 107640 KB Output is correct
33 Correct 347 ms 107184 KB Output is correct
34 Correct 491 ms 146808 KB Output is correct
35 Correct 497 ms 145784 KB Output is correct
36 Correct 502 ms 147116 KB Output is correct
37 Correct 506 ms 144928 KB Output is correct
38 Correct 498 ms 146680 KB Output is correct
39 Correct 495 ms 145284 KB Output is correct
40 Correct 493 ms 146184 KB Output is correct
41 Correct 497 ms 146328 KB Output is correct
42 Correct 497 ms 145004 KB Output is correct
43 Correct 503 ms 146424 KB Output is correct
44 Correct 500 ms 145332 KB Output is correct
45 Correct 499 ms 145144 KB Output is correct
46 Correct 504 ms 146216 KB Output is correct
47 Correct 514 ms 153348 KB Output is correct
48 Correct 513 ms 153396 KB Output is correct
49 Correct 525 ms 153336 KB Output is correct
50 Correct 5 ms 256 KB Output is correct
51 Correct 6 ms 760 KB Output is correct
52 Correct 5 ms 376 KB Output is correct
53 Execution timed out 2117 ms 693624 KB Time limit exceeded
54 Halted 0 ms 0 KB -