QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#810642#8874. Labelled Pathsrealcomplex0WA 1ms7668kbC++203.1kb2024-12-12 03:46:172024-12-12 03:46:17

Judging History

This is the latest submission verdict.

  • [2024-12-12 03:46:17]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 7668kb
  • [2024-12-12 03:46:17]
  • Submitted

answer

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

struct Edge{
    int nex;
    int l;
    int r;
};

const int N = 610;
const int MOD = (int)1e9 + 9;
const int B = 77;
const int L = (int)1e6 + 10;
int d;

int id[L];
int pwr[L];
int cum[L];

vector<Edge> E[N];

int get_hash(int l, int r){
    int sum = (cum[r] - cum[l - 1] + MOD) % MOD;
    return (sum * 1ll * pwr[d - r]) % MOD;
}

bool is_equal(int l1, int r1, int l2, int r2){
    return get_hash(l1,r1) == get_hash(l2,r2);
}

int ci = 0;

bool cmp(vector<Edge> A, vector<Edge> B){ // is A < B
    int i = 0, j = 0;
    ci ++ ;
    while(i < A.size() && j < B.size()){
        int len = min(A[i].r - A[i].l, B[j].r - B[j].l) + 1;
        if(len == 0 || is_equal(A[i].l, A[i].l + len - 1, B[j].l, B[j].l + len - 1)){
            A[i].l += len;
            B[j].l += len;
            if(A[i].l > A[i].r) i ++ ;
            if(B[j].l > B[j].r) j ++ ;
        }
        else{
            // find the difference point with binary search and then just compare (;
            int lf = 0, rf = len - 1;
            while(lf < rf){
                int mid = (lf + rf) / 2;
                if(is_equal(A[i].l, A[i].l + mid, B[j].l, B[j].l + mid)){
                    lf = mid + 1;
                }
                else{
                    rf = mid;
                }
            }
            int ii = A[i].l + lf;
            int jj = B[j].l + lf;
            if(id[ii] < id[jj]) return true;
            else return false;
        }
    }
    if(j == B.size()){
        return false;
    }
    else{
        return true;
    }
}

bool vis[N];
bool has[N];
vector<Edge> P[N];

vector<int> ord;
void dfs(int u){
    if(vis[u]) return;
    vis[u]=true;
    for(auto x : E[u]){
        dfs(x.nex);
    }
    ord.push_back(u);
}

int main(){
    fastIO;
    int n, m, s;
    cin >> n >> m >> d >> s;
    int u, v, l, r;
    pwr[0] = 1;
    for(int i = 1; i <= d; i ++ ){
        char f;
        cin >> f;
        id[i] = f - 'a' + 1;
        pwr[i] = (pwr[i - 1] * 1ll * B) % MOD;
        cum[i] = (cum[i - 1] + (pwr[i] * 1ll * id[i]) % MOD) % MOD;
    }
    for(int i = 1; i <= m ; i ++ ){
        cin >> u >> v >> l >> r;
        r = r + l - 1;
        E[u].push_back({v, l, r});
    }
    dfs(s);
    reverse(ord.begin(), ord.end());
    has[s]=true;
    for(auto id : ord){
        if(!has[id]) continue;
        for(auto e : E[id]){
            vector<Edge> X = P[id];
            X.push_back(e);
            if(!has[e.nex] || cmp(X, P[e.nex])){
                P[e.nex] = X;
                has[e.nex]=true;
            }
        }
    }
    for(int it = 1; it <= n; it ++ ){
        if(!has[it]) cout << "0\n";
        else{
            cout << 1 + P[it].size() << " " << s << " ";
            for(auto x : P[it]){
                cout << x.nex << " ";
            }
            cout << "\n";
        }
    }
    return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 7668kb

input:

11 30 105 9
fufuffuffuuuuuufuffuffuufffuufufuuuuuuuuuufffufufffuuufuffufufuuffffuufffuffffuffffufuuuufuufuuffuuuufffu
1 6 51 1
5 2 6 1
9 6 57 3
11 8 86 4
10 8 95 0
6 2 17 0
6 3 78 0
7 3 50 0
11 4 98 3
10 3 77 3
5 4 18 4
7 4 81 1
9 7 82 0
1 3 79 2
7 5 13 4
1 10 86 2
10 4 10 0
9 3 4 0
6 11 10 4
6 4 82...

output:

2 9 1 
3 9 1 2 
2 9 3 
3 9 7 4 
3 9 1 5 
3 9 1 6 
2 9 7 
3 9 3 8 
1 9 
3 9 1 10 
3 9 7 11 

result:

wrong answer wrong solution for vertex 8