QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#385511#5110. SplitstreamSolitaryDream#WA 0ms6684kbC++172.8kb2024-04-10 20:30:382024-04-10 20:30:38

Judging History

你现在查看的是最新测评结果

  • [2024-04-10 20:30:38]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:6684kb
  • [2024-04-10 20:30:38]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

const int N=1e5+1e3+7;

int n,m,Q;

int len[N];

int ty[N];

int fa[N],in[N][2];

int deg[N];

vector<int> g[N];

map<int,int>idx;

int id(int x)
{
    if(!idx.count(x))
        idx[x]=idx.size()+1;
    return idx[x];
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>m>>n>>Q;
    int cnt=n*3;
    for(int i=1;i<=n;i++)
    {
        string s;
        cin>>s;
        int x=++cnt;
        int a,b,c;
        cin>>a>>b>>c;
        a=id(a);
        b=id(b);
        c=id(c);
        if(s[0]=='S')
        {
            g[a].push_back(x);
            deg[x]++;
            g[x].push_back(b),g[x].push_back(c);
            deg[b]++,deg[c]++;
            fa[b]=x,fa[c]=x;
            in[x][0]=a;
        }
        else
        {
            ty[x]=1;
            g[a].push_back(x),g[b].push_back(x);
            deg[x]+=2;
            in[x][0]=a,in[x][1]=b;
            g[x].push_back(c);
            deg[c]++;
            fa[c]=x;
        }
    }
    vector<int> sp;
    queue<int> q;
    q.push(1);
    while(!q.empty())
    {
        int x=q.front();
        q.pop();
        sp.push_back(x);
        for(auto v:g[x])
        {
            if(!--deg[v])
                q.push(v);
        }
    }
    len[1]=m;
    for(auto x:sp)
    {
        for(auto v:g[x])
        {
            if(v>n*3)
                len[v]+=len[x];
            else
            {
                assert(x>n*3);
                if(ty[x]==0)
                {
                    if(v==g[x][1])
                        len[v]+=len[x]/2;
                    else
                        len[v]+=(len[x]+1)/2;
                }
                else
                    len[v]+=len[x];
            }
        }
    }
    while(Q--)
    {
        int x,k;
        cin>>x>>k;
        x=id(x);
        if(k>len[x])
            cout<<"none\n";
        else
        {
            while(x!=1)
            {
                int z=fa[x];
                assert(z>n*3);
                if(ty[z]==0)
                {
                    k=k*2-(x==g[z][0]);
                    x=in[z][0];
                }
                else
                {
                    int mn=min(len[in[z][0]],len[in[z][1]]);
                    if(k<=mn*2)
                    {
                        if(k%2==1)
                            x=in[z][0];
                        else
                            x=in[z][1];
                        k=(k+1)/2;
                    }
                    else
                    {
                        int f=len[in[z][0]]<len[in[z][1]];
                        x=in[z][f];
                        k=k-mn;
                    }
                }
            }
            cout<<k<<"\n";
        }
    }
}

详细

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 6684kb

input:

5 8 26
M 8 9 13
S 2 4 5
S 1 2 3
M 6 5 8
S 4 9 10
S 10 14 15
S 3 6 7
S 7 11 12
2 3
2 4
3 2
3 3
4 2
4 3
5 1
5 2
6 1
6 2
7 1
7 2
8 2
8 3
9 1
9 2
10 1
10 2
11 1
11 2
12 1
13 3
13 4
14 1
14 2
15 1

output:

none
none
none
none
none
none
none
none
none
none
none
none
2
3
none
none
none
none
none
none
none
none
none
none
none
none

result:

wrong answer 1st lines differ - expected: '5', found: 'none'