Submission #339377

# Submission time Handle Problem Language Result Execution time Memory
339377 2020-12-25T07:03:38 Z ijxjdjd Selling RNA Strands (JOI16_selling_rna) Java 11
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef string str;
typedef double db;
typedef long double ld;

typedef pair<int, int> pi;
typedef  pair<ll, ll> pl;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;


#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define FR(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define RF(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)
const int MAXN = (int)(1e5) + 5;
const int MAXNODES = (int)(2e6) + 5;
struct Node {
    int to[4] = {-1, -1, -1, -1};
    int leaf = -1;
    int cnt = 0;
};
vi prefix[MAXN];
vi suffix[MAXN];
int cur[MAXN];
int ans[MAXN];
vector<Node> nodes;
vi ss[MAXN];
vi ssrev[MAXN];
struct Trie {
    int root = -1;
    vector<int> leaves;
    int sz = 0;
    Trie() {
        root = nodes.size();
        nodes.push_back({});
    }
    void add(int i, vi& a) {
        sz += a.size();
        leaves.push_back(i);
        iter(root, 0, i, a);
    }
    void iter(int j, int cur, int i, vi& s) {
        nodes[j].cnt++;
        if (cur == s.size()-1) {
            nodes[j].leaf = i;
            return;
        }
        if (nodes[j].to[s[cur]] == -1) {
            nodes[j].to[s[cur]] = nodes.size();
            nodes.push_back({});
        }
        iter(nodes[j].to[s[cur]], cur+1, i, s);
    }
    int cnt(vi& a, int u, int cur = 0) {
        if (u == -1) {
            return 0;
        }
        if (cur == a.size()) {
            return nodes[u].cnt;
        }
        return cnt(a, nodes[u].to[a[cur]], cur+1);
    }
};
Trie start;
Trie ts[MAXN];
int tr[MAXNODES];
int merge(int u, int j) {
    if (ts[u].sz < ts[j].sz) {
        swap(u, j);
    }
    trav(v, ts[j].leaves) {
        ts[u].add(v, ssrev[v]);
    }
    return u;
}
void dfs(int u, vi& prefixes) {
    if (nodes[u].leaf != -1) {
        tr[u] = nodes[u].leaf;
    }
    vi send[5];
    trav(a, prefixes) {
        if (cur[a] == prefix[a].size()) {
            send[4].push_back(a);
        }
        else {
            send[prefix[a][cur[a]++]].push_back(a);
        }
    }
    FR(i, 4) {
        if (nodes[u].to[i] != -1) {
            dfs(nodes[u].to[i], send[i]);
            if (tr[u] == -1) {
                tr[u] = tr[nodes[u].to[i]];
            }
            else {
                tr[u] = merge(tr[u], tr[nodes[u].to[i]]);
            }
        }
    }
    trav(a, send[4]) {
        ans[a] = ts[tr[u]].cnt(suffix[a], ts[tr[u]].root);
    }

}
int conv[300];
int main() {
    int N, M;
    cin >> N >> M;
    conv['A'] = 0;
    conv['G'] = 1;
    conv['C'] = 2;
    conv['U'] = 3;
    FR(i, MAXNODES) {
        tr[i] = -1;
    }
    FR(i, N) {
        string t;
        cin >> t;
        FR(j, t.size()) {
            ss[i].push_back(conv[t[j]]);
            ssrev[i].push_back(conv[t[j]]);
        }
        reverse(ssrev[i].begin(), ssrev[i].end());
        start.add(i, ss[i]);
        ts[i].add(i, ssrev[i]);
    }
    vi ori;
    FR(i, M) {
        string pre, suff;
        cin >> pre >> suff;
        FR(j, pre.size()) {
            prefix[i].push_back(conv[pre[j]]);
        }
        FR(j, suff.size()) {
            suffix[i].push_back(conv[suff[j]]);
        }
        reverse(suffix[i].begin(), suffix[i].end());
        ori.push_back(i);
    }
    dfs(start.root, ori);
    FR(i, M) {
        cout << ans[i] << '\n';
    }
}

Compilation message

selling_rna.java:1: error: illegal character: '#'
#include <bits/stdc++.h>
^
selling_rna.java:1: error: class, interface, or enum expected
#include <bits/stdc++.h>
         ^
selling_rna.java:4: error: class, interface, or enum expected
typedef long long ll;
^
selling_rna.java:5: error: class, interface, or enum expected
typedef string str;
^
selling_rna.java:6: error: class, interface, or enum expected
typedef double db;
^
selling_rna.java:7: error: class, interface, or enum expected
typedef long double ld;
^
selling_rna.java:9: error: class, interface, or enum expected
typedef pair<int, int> pi;
^
selling_rna.java:10: error: class, interface, or enum expected
typedef  pair<ll, ll> pl;
^
selling_rna.java:12: error: class, interface, or enum expected
typedef vector<int> vi;
^
selling_rna.java:13: error: class, interface, or enum expected
typedef vector<ll> vl;
^
selling_rna.java:14: error: class, interface, or enum expected
typedef vector<pi> vpi;
^
selling_rna.java:17: error: illegal character: '#'
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
^
selling_rna.java:17: error: class, interface, or enum expected
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
        ^
selling_rna.java:17: error: class, interface, or enum expected
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
                                     ^
selling_rna.java:17: error: class, interface, or enum expected
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
                                              ^
selling_rna.java:18: error: illegal character: '#'
#define FR(i,a) FOR(i,0,a)
^
selling_rna.java:19: error: illegal character: '#'
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
^
selling_rna.java:19: error: class, interface, or enum expected
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
                                       ^
selling_rna.java:19: error: class, interface, or enum expected
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
                                                 ^
selling_rna.java:20: error: illegal character: '#'
#define RF(i,a) ROF(i,0,a)
^
selling_rna.java:21: error: illegal character: '#'
#define trav(a,x) for (auto& a: x)
^
selling_rna.java:23: error: class, interface, or enum expected
const int MAXNODES = (int)(2e6) + 5;
^
selling_rna.java:24: error: class, interface, or enum expected
struct Node {
^
selling_rna.java:26: error: class, interface, or enum expected
    int leaf = -1;
    ^
selling_rna.java:27: error: class, interface, or enum expected
    int cnt = 0;
    ^
selling_rna.java:28: error: class, interface, or enum expected
};
^
selling_rna.java:29: error: class, interface, or enum expected
vi prefix[MAXN];
^
selling_rna.java:30: error: class, interface, or enum expected
vi suffix[MAXN];
^
selling_rna.java:31: error: class, interface, or enum expected
int cur[MAXN];
^
selling_rna.java:32: error: class, interface, or enum expected
int ans[MAXN];
^
selling_rna.java:33: error: class, interface, or enum expected
vector<Node> nodes;
^
selling_rna.java:34: error: class, interface, or enum expected
vi ss[MAXN];
^
selling_rna.java:35: error: class, interface, or enum expected
vi ssrev[MAXN];
^
selling_rna.java:36: error: class, interface, or enum expected
struct Trie {
^
selling_rna.java:38: error: class, interface, or enum expected
    vector<int> leaves;
    ^
selling_rna.java:39: error: class, interface, or enum expected
    int sz = 0;
    ^
selling_rna.java:40: error: class, interface, or enum expected
    Trie() {
    ^
selling_rna.java:42: error: class, interface, or enum expected
        nodes.push_back({});
        ^
selling_rna.java:43: error: class, interface, or enum expected
    }
    ^
selling_rna.java:46: error: class, interface, or enum expected
        leaves.push_back(i);
        ^
selling_rna.java:47: error: class, interface, or enum expected
        iter(root, 0, i, a);
        ^
selling_rna.java:48: error: class, interface, or enum expected
    }
    ^
selling_rna.java:51: error: class, interface, or enum expected
        if (cur == s.size()-1) {
        ^
selling_rna.java:53: error: class, interface, or enum expected
            return;
            ^
selling_rna.java:54: error: class, interface, or enum expected
        }
        ^
selling_rna.java:57: error: class, interface, or enum expected
            nodes.push_back({});
            ^
selling_rna.java:58: error: class, interface, or enum expected
        }
        ^
selling_rna.java:60: error: class, interface, or enum expected
    }
    ^
selling_rna.java:64: error: class, interface, or enum expected
        }
        ^
selling_rna.java:67: error: class, interface, or enum expected
        }
        ^
selling_rna.java:69: error: class, interface, or enum expected
    }
    ^
selling_rna.java:71: error: class, interface, or enum expected
Trie start;
^
selling_rna.java:72: error: class, interface, or enum expected
Trie ts[MAXN];
^
selling_rna.java:73: error: class, interface, or enum expected
int tr[MAXNODES];
^
selling_rna.java:74: error: class, interface, or enum expected
int merge(int u, int j) {
^
selling_rna.java:77: error: class, interface, or enum expected
    }
    ^
selling_rna.java:80: error: class, interface, or enum expected
    }
    ^
selling_rna.java:82: error: class, interface, or enum expected
}
^
selling_rna.java:86: error: class, interface, or enum expected
    }
    ^
selling_rna.java:88: error: class, interface, or enum expected
    trav(a, prefixes) {
    ^
selling_rna.java:91: error: class, interface, or enum expected
        }
        ^
selling_rna.java:94: error: class, interface, or enum expected
        }
        ^
selling_rna.java:99: error: class, interface, or enum expected
            if (tr[u] == -1) {
            ^
selling_rna.java:101: error: class, interface, or enum expected
            }
            ^
selling_rna.java:104: error: class, interface, or enum expected
            }
            ^
selling_rna.java:109: error: class, interface, or enum expected
    }
    ^
selling_rna.java:113: error: class, interface, or enum expected
int main() {
^
selling_rna.java:115: error: class, interface, or enum expected
    cin >> N >> M;
    ^
selling_rna.java:116: error: class, interface, or enum expected
    conv['A'] = 0;
    ^
selling_rna.java:117: error: class, interface, or enum expected
    conv['G'] = 1;
    ^
selling_rna.java:118: error: class, interface, or enum expected
    conv['C'] = 2;
    ^
selling_rna.java:119: error: class, interface, or enum expected
    conv['U'] = 3;
    ^
selling_rna.java:120: error: class, interface, or enum expected
    FR(i, MAXNODES) {
    ^
selling_rna.java:122: error: class, interface, or enum expected
    }
    ^
selling_rna.java:125: error: class, interface, or enum expected
        cin >> t;
        ^
selling_rna.java:126: error: class, interface, or enum expected
        FR(j, t.size()) {
        ^
selling_rna.java:128: error: class, interface, or enum expected
            ssrev[i].push_back(conv[t[j]]);
            ^
selling_rna.java:129: error: class, interface, or enum expected
        }
        ^
selling_rna.java:131: error: class, interface, or enum expected
        start.add(i, ss[i]);
        ^
selling_rna.java:132: error: class, interface, or enum expected
        ts[i].add(i, ssrev[i]);
        ^
selling_rna.java:133: error: class, interface, or enum expected
    }
    ^
selling_rna.java:135: error: class, interface, or enum expected
    FR(i, M) {
    ^
selling_rna.java:137: error: class, interface, or enum expected
        cin >> pre >> suff;
        ^
selling_rna.java:138: error: class, interface, or enum expected
        FR(j, pre.size()) {
        ^
selling_rna.java:140: error: class, interface, or enum expected
        }
        ^
selling_rna.java:143: error: class, interface, or enum expected
        }
        ^
selling_rna.java:145: error: class, interface, or enum expected
        ori.push_back(i);
        ^
selling_rna.java:146: error: class, interface, or enum expected
    }
    ^
selling_rna.java:148: error: class, interface, or enum expected
    FR(i, M) {
    ^
selling_rna.java:150: error: class, interface, or enum expected
    }
    ^
90 errors