QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#760262#9349. Exchanging Gifts_Rosetta_WA 73ms66232kbC++143.6kb2024-11-18 15:52:012024-11-18 15:52:02

Judging History

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

  • [2024-11-18 15:52:02]
  • 评测
  • 测评结果:WA
  • 用时:73ms
  • 内存:66232kb
  • [2024-11-18 15:52:01]
  • 提交

answer

#include<bits/stdc++.h>
#define fo(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout)
#define rep(i,l,r) for(ll i(l),i##end(r);i<=i##end;++i)
#define per(i,r,l) for(ll i(r),i##end(l);i>=i##end;--i)
#define dbg(x) cerr<<#x<<" "<<x<<'\n';
#define ll long long
#define gc getchar
#define pc putchar
using namespace std;
namespace WrongIO
{
	#define Ts template<typename Ty,typename... Ar>
	#define Tp template<typename Ty>
	Tp Ty wmax(Ty a,Ty b){return a>=b? a:b;}
	Tp Ty wmin(Ty a,Ty b){return a<=b? a:b;}
	Tp void read(Ty &x){x=0;Ty opt=1;char c=gc();while(!isdigit(c)&&c!='-')c=gc();if(c=='-')opt=-1,c=gc();while(isdigit(c))x=(x<<3)+(x<<1),x+=c-'0',c=gc();x*=opt;return;}
	Tp void write(Ty x){short OI_USE[150],OI_top=0;if(x<=0) if(x==0)pc('0');else pc('-'),x*=-1;while(x)OI_USE[++OI_top]=x%10,x/=10;while(OI_top--)pc(OI_USE[OI_top+1]+'0');return;}
    void writec(char c[]){int len=strlen(c);for(int i=0;i<len;i++)pc(c[i]);}
    void writes(string s){int len=s.length();for(int i=0;i<len;i++)pc(s[i]);}
    void readc(char &c,int l,int r){c=gc(); while(c!=EOF&&(c<l||c>r)) c=gc();}
    void readc(char &c,char val){c=gc();while(c!=EOF&&c!=val) c=gc();}
    void readc(char val){char c;c=gc();while(c!=EOF&&c!=val) c=gc();}
    void readls(string &s){char c=gc();while(c!='\n') s.push_back(c),c=gc();}
    Ts void read(Ty &x,Ar &...y) {read(x),read(y...);}
    Tp void writeln(Ty x) {write(x),pc('\n');}
    Tp void writesp(Ty x) {write(x),pc(' ');} 
    #undef Ts
	#undef Tp
} using namespace WrongIO;
struct awa{
    vector<ll> s;
    ll s1,s2;
    ll num,kind,len;
    void clear()
    {
        s.clear(); num=0; kind=0;
        s1=s2=-1; len=0;
    }
}e[1000050];
ll T,n;

int main()
{
    read(T);
    while(T--)
    {
        read(n);
        rep(i,1,n)
        {
            e[i].clear();
            ll opt; read(opt);
            if(opt==1)
            {
                ll m; read(m); e[i].len=m;
                rep(j,1,m)
                {
                    ll tp; read(tp);// dbg(tp); dbg(e[i].s.size());
                    if(e[i].num==0)
                    {
                        e[i].num=1,e[i].kind=tp;
                    }else{
                        if(e[i].kind==tp) e[i].num++; else e[i].num--;
                    } 
                    // dbg(e[i].num);
                    e[i].s.push_back(tp);
                }

            }
            if(opt==2)
            {
                read(e[i].s1,e[i].s2);
                ll t1=e[i].s1,t2=e[i].s2;
                if(e[t1].kind==e[t2].kind)
                {
                    e[i].num=e[t1].num+e[t2].num;
                    e[t1].kind=e[t2].kind;
                }else{
                    if(e[t1].num<e[t2].num) swap(t1,t2);
                    e[i].kind=e[t1].kind;
                    e[i].num=e[t1].num-e[t2].num;
                }
                e[i].len=e[t1].len+e[t2].len;
            }
        }
        ll kd=e[n].kind;
        rep(i,1,n)
        {
            e[i].num=0;
            if(e[i].s1==-1)
            {
                for(ll j=0;j<e[i].len;j++)
                {
                    ll tp=e[i].s[j];
                    // dbg(tp);
                    if(tp==kd) e[i].num++;
                }
                
            }else e[i].num=e[e[i].s1].num+e[e[i].s2].num;
        }
        // rep(i,1,n)
        // {
        //     dbg(i); dbg(e[i].kind); dbg(e[i].num);
        // }
        if(e[n].num>e[n].len/2) writeln(2*(e[n].len-e[n].num));
        else writeln(e[n].len);
    }
}

//g++ .Yuria.cpp -o rst -std=c++17

詳細信息

Test #1:

score: 100
Accepted
time: 4ms
memory: 66144kb

input:

2
1
1 5 3 3 2 1 3
3
1 3 3 3 2
1 4 2 2 3 3
2 1 2

output:

4
6

result:

ok 2 lines

Test #2:

score: -100
Wrong Answer
time: 73ms
memory: 66232kb

input:

10000
100
1 30 371028678 371028678 371028678 716418076 398221499 591504380 398221499 398221499 591504380 777141390 398221499 591504380 591504380 777141390 287847807 716418076 777141390 716418076 777141390 287847807 287847807 287847807 371028678 371028678 398221499 777141390 371028678 6827702 6827702...

output:

700
68
332
311
131
1048
194
667
754
640
532
252
35
351
1228
238
1025
354
383
571
4272
340
1044
199
448
190
1459
69
841
546
247
883
138
1633
91
3308
2556
1280
488
618
407
381
383
2865
1407
496
1202
53
154
415
662
380
41
18
91
505
818
603
241
764
1227
1802
176
187
817
1489
460
296
238
259
1028
190
606...

result:

wrong answer 4th lines differ - expected: '284', found: '311'