답안 #78841

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
78841 2018-10-09T06:26:50 Z win11905 Selling RNA Strands (JOI16_selling_rna) C++11
100 / 100
1438 ms 533240 KB
#include <bits/stdc++.h>
using namespace std;

#define pii pair<int, int>
#define x first
#define y second
#define all(x) x.begin(), x.end()

struct coorh {
    size_t operator()(const pii &a) const {
        return a.x + a.y;
    }
};

int n, m;

pii add(pii a, pii b) { return pii(a.x + b.x, a.y + b.y); }
pii mul(pii a, pii b) { return pii(a.x * b.x, a.y * b.y); }

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> m;
    vector<string> str;
    for(int i = 0; i < n; ++i) {
        string now; cin >> now;
        str.emplace_back(now);
    }
    sort(all(str));
    unordered_map<pii, vector<int>, coorh> hr(20000000);
    unordered_map<pii, pii, coorh> hl(20000000);
    for(int i = 0; i < n; ++i) {
        int len = str[i].size();
        pii hashl, hashr;
        for(int j = 0; j < len; ++j) {
            hashl = add(mul(hashl, pii(131, 133)), pii(str[i][j], str[i][j]));
            if(hl.count(hashl)) hl[hashl].y = i;
            else hl[hashl] = pii(i, i);
        }
        for(int j = len-1; ~j; --j) 
            hashr = add(mul(hashr, pii(131, 133)), pii(str[i][j], str[i][j])), hr[hashr].emplace_back(i);
    }
    for(int i = 0; i < m; ++i) {
        string a, b; cin >> a >> b;
        pii hashl, hashr;
        for(int j = 0; j < a.size(); ++j) 
            hashl = add(mul(hashl, pii(131, 133)), pii(a[j], a[j]));
        for(int j = b.size()-1; ~j; --j) 
            hashr = add(mul(hashr, pii(131, 133)), pii(b[j], b[j]));
        if(!hl.count(hashl)) {
            puts("0");
            continue;
        }
        int l = hl[hashl].x, r = hl[hashl].y;
        int dis = upper_bound(all(hr[hashr]), r) - lower_bound(all(hr[hashr]), l);
        printf("%d\n", dis);
    }
}

Compilation message

selling_rna.cpp: In function 'int main()':
selling_rna.cpp:46:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int j = 0; j < a.size(); ++j) 
                        ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 322 ms 329592 KB Output is correct
2 Correct 323 ms 329656 KB Output is correct
3 Correct 326 ms 329656 KB Output is correct
4 Correct 328 ms 329656 KB Output is correct
5 Correct 321 ms 329712 KB Output is correct
6 Correct 335 ms 329712 KB Output is correct
7 Correct 326 ms 329792 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1438 ms 518916 KB Output is correct
2 Correct 1360 ms 518916 KB Output is correct
3 Correct 1143 ms 518916 KB Output is correct
4 Correct 1094 ms 518916 KB Output is correct
5 Correct 1190 ms 519464 KB Output is correct
6 Correct 1156 ms 524456 KB Output is correct
7 Correct 692 ms 524456 KB Output is correct
8 Correct 1128 ms 524456 KB Output is correct
9 Correct 1020 ms 524456 KB Output is correct
10 Correct 920 ms 524456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 365 ms 524456 KB Output is correct
2 Correct 370 ms 524456 KB Output is correct
3 Correct 370 ms 524456 KB Output is correct
4 Correct 359 ms 524456 KB Output is correct
5 Correct 364 ms 524456 KB Output is correct
6 Correct 373 ms 524456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 322 ms 329592 KB Output is correct
2 Correct 323 ms 329656 KB Output is correct
3 Correct 326 ms 329656 KB Output is correct
4 Correct 328 ms 329656 KB Output is correct
5 Correct 321 ms 329712 KB Output is correct
6 Correct 335 ms 329712 KB Output is correct
7 Correct 326 ms 329792 KB Output is correct
8 Correct 1438 ms 518916 KB Output is correct
9 Correct 1360 ms 518916 KB Output is correct
10 Correct 1143 ms 518916 KB Output is correct
11 Correct 1094 ms 518916 KB Output is correct
12 Correct 1190 ms 519464 KB Output is correct
13 Correct 1156 ms 524456 KB Output is correct
14 Correct 692 ms 524456 KB Output is correct
15 Correct 1128 ms 524456 KB Output is correct
16 Correct 1020 ms 524456 KB Output is correct
17 Correct 920 ms 524456 KB Output is correct
18 Correct 365 ms 524456 KB Output is correct
19 Correct 370 ms 524456 KB Output is correct
20 Correct 370 ms 524456 KB Output is correct
21 Correct 359 ms 524456 KB Output is correct
22 Correct 364 ms 524456 KB Output is correct
23 Correct 373 ms 524456 KB Output is correct
24 Correct 1244 ms 527008 KB Output is correct
25 Correct 1254 ms 531404 KB Output is correct
26 Correct 1254 ms 533240 KB Output is correct
27 Correct 1010 ms 533240 KB Output is correct
28 Correct 751 ms 533240 KB Output is correct
29 Correct 482 ms 533240 KB Output is correct