QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#188455#5504. Flower GardenAPJifengcWA 1821ms134176kbC++147.5kb2023-09-25 20:51:022023-09-25 20:51:03

Judging History

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

  • [2023-09-25 20:51:03]
  • 评测
  • 测评结果:WA
  • 用时:1821ms
  • 内存:134176kb
  • [2023-09-25 20:51:02]
  • 提交

answer

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

namespace FastIO
{

class FastIOBase
{
 protected:
#ifdef OPENIOBUF
    static const int BUFSIZE=1<<22;
    char buf[BUFSIZE+1];
    int buf_p=0;
#endif
    FILE *target;
 public:
#ifdef OPENIOBUF
    virtual void flush()=0;
#endif
    FastIOBase(FILE *f): target(f){}
    ~FastIOBase()=default;
};

class FastOutput: public FastIOBase
{
#ifdef OPENIOBUF
 public:
    inline void flush()
        { fwrite(buf,1,buf_p,target),buf_p=0; }
#endif
 protected:
    inline void __putc(char x)
    {
#ifdef OPENIOBUF
        if(buf[buf_p++]=x,buf_p==BUFSIZE)flush();
#else
        putc(x,target);
#endif
    }
    template<typename T>
    inline void __write(T x)
    {
        static char stk[64],*top;top=stk;
        if(x<0) return __putc('-'),__write(-x);
        do *(top++)=x%10,x/=10; while(x);
        for(;top!=stk;__putc(*(--top)+'0'));
    }
 public:
    FastOutput(FILE *f=stdout): FastIOBase(f){}
#ifdef OPENIOBUF
    inline void setTarget(FILE *f) { this->flush(),target=f; }
    ~FastOutput(){ flush(); }
#else
    inline void setTarget(FILE *f) { target=f; }
#endif
    template<typename ...T>
    inline void writesp(const T &...x)
        { initializer_list<int>{(this->operator<<(x),__putc(' '),0)...}; }
    template<typename ...T>
    inline void writeln(const T &...x)
        { initializer_list<int>{(this->operator<<(x),__putc('\n'),0)...}; }
    inline FastOutput &operator <<(char x)
        { return __putc(x),*this; }
    inline FastOutput &operator <<(const char *s)
        { for(;*s;__putc(*(s++)));return *this; }
    inline FastOutput &operator <<(const string &s)
        { return (*this)<<s.c_str(); }
    template<typename T,typename=typename enable_if<is_integral<T>::value>::type>
    inline FastOutput &operator <<(const T &x)
        { return __write(x),*this; }
}qout;

class FastInput: public FastIOBase
{
#ifdef OPENIOBUF
 public:
    inline void flush()
        { buf[fread(buf,1,BUFSIZE,target)]='\0',buf_p=0; }
#endif
 protected:
    inline char __getc()
    {
#ifdef OPENIOBUF
        if(buf_p==BUFSIZE) flush();
        return buf[buf_p++];
#else
        return getc(target);
#endif
    }
 public:
#ifdef OPENIOBUF
    FastInput(FILE *f=stdin): FastIOBase(f){ buf_p=BUFSIZE; }
    inline void setTarget(FILE *f) { this->flush(),target=f; }
#else
    FastInput(FILE *f=stdin): FastIOBase(f){}
    inline void setTarget(FILE *f) { target=f; }
#endif
    inline char getchar() { return __getc(); }
    template<typename ...T>
    inline void read(T &...x)
        { initializer_list<int>{(this->operator>>(x),0)...}; }
    inline FastInput &operator >>(char &x)
        { while(isspace(x=__getc()));return *this; }
    template<typename T,typename=typename enable_if<is_integral<T>::value>::type>
    inline FastInput &operator >>(T &x)
    {
        static char ch,sym;x=sym=0;
        while(isspace(ch=__getc()));
        if(ch=='-') sym=1,ch=__getc();
        for(;isdigit(ch);x=(x<<1)+(x<<3)+(ch^48),ch=__getc());
        return sym?x=-x:x,*this;
    }
    inline FastInput &operator >>(char *s)
    {
        while(isspace(*s=__getc()));
        for(;!isspace(*s) && *s && ~*s;*(++s)=__getc());
        return *s='\0',*this;
    }
    inline FastInput &operator >>(string &s)
    {
        char str_buf[(1<<8)+1],*p=str_buf;
        char *const buf_end=str_buf+(1<<8);
        while(isspace(*p=__getc()));
        for(s.clear(),p++;;p=str_buf)
        {
            for(;p!=buf_end && !isspace(*p=__getc()) && *p && ~*p;p++);
            *p='\0',s.append(str_buf);
            if(p!=buf_end) break;
        }
        return *this;
    }
}qin;

} // namespace FastIO
using namespace FastIO;

using LL=long long;
using LD=long double;
using UI=unsigned int;
using ULL=unsigned long long;

#ifndef DADALZY
#define FILEIO(file) freopen(file".in","r",stdin),freopen(file".out","w",stdout)
#else
#define FILEIO(file)
#endif

int T,n,q,lim,nn,w[400005];
char ans[400005];
vector<int> g1[400005],g2[400005],gr[400005];

struct TreeNode{ int id1,id2; }t[400005];
#define LC (i<<1)
#define RC (i<<1|1)
void build(int l,int r,int i=1)
{
    if(l==r) return t[i].id1=t[i].id2=l,void();
    t[i].id1=++nn,t[i].id2=++nn;
    int mid=(l+r)>>1;
    build(l,mid,LC),build(mid+1,r,RC);
    g1[t[i].id1].push_back(t[LC].id1);
    g1[t[LC].id2].push_back(t[i].id2);
    g1[t[i].id1].push_back(t[RC].id1);
    g1[t[RC].id2].push_back(t[i].id2);
}
void addEdgeFrom(int lq,int rq,int x,int i=1,int l=1,int r=n)
{
    if(l>=lq && r<=rq) return g1[t[i].id2].push_back(x);
    int mid=(l+r)>>1;
    if(mid>=lq) addEdgeFrom(lq,rq,x,LC,l,mid);
    if(mid<rq) addEdgeFrom(lq,rq,x,RC,mid+1,r);
}
void addEdgeTo(int lq,int rq,int x,int i=1,int l=1,int r=n)
{
    if(l>=lq && r<=rq) return g1[x].push_back(t[i].id1);
    int mid=(l+r)>>1;
    if(mid>=lq) addEdgeTo(lq,rq,x,LC,l,mid);
    if(mid<rq) addEdgeTo(lq,rq,x,RC,mid+1,r);
}

int tot,ccnt,top,dfn[400005],low[400005],col[400005],stk[400005];
bool vis[400005];
void tarjan(int u)
{
    dfn[u]=low[u]=++tot;
    stk[++top]=u,vis[u]=true;
    for(auto &v: g1[u])
        if(!dfn[v]) tarjan(v),low[u]=min(low[u],low[v]);
        else if(vis[v]) low[u]=min(low[u],dfn[v]);
    if(dfn[u]==low[u])
    {
        int x,y=++ccnt;
        do x=stk[top--],vis[x]=false,col[x]=y;
        while(x!=u);
    }
}
bool solve1(int S)
{
    queue<int> q;
    int sum=0;
    fill(vis+1,vis+nn+1,false);
    fill(ans+1,ans+nn+1,'R');
    q.push(S),vis[S]=true;
    while(!q.empty())
    {
        int u=q.front();
        for(auto &v: g2[u])
            if(!vis[v]) q.push(v),vis[v]=true;
        sum+=w[u],ans[u]='F',q.pop();
    }
    return sum>=lim && sum<=2*lim;
}
bool solve2()
{
    static int deg[400005];
    queue<int> q;
    int sum=0;
    for(int u=1;u<=nn;u++) deg[u]=gr[u].size();
    for(int u=1;u<=nn;u++) if(!deg[u]) q.push(u);
    fill(ans+1,ans+nn+1,'F');
    while(!q.empty())
    {
        int u=q.front();
        sum+=w[u],ans[u]='R',q.pop();
        if(sum>=lim && sum<=2*lim) return true;
        for(auto &v: g2[u]) if(!--deg[v]) q.push(v);
    }
    return false; // shouldn't appear
}
int main()
{
    qin>>T;
    while(T--)
    {
        qin>>lim>>q,n=3*lim,nn=n;
        build(1,n);
        for(int i=1;i<=q;i++)
        {
            int a,b,c,d;
            qin>>a>>b>>c>>d,nn++;
            addEdgeFrom(a,b,nn);
            addEdgeTo(c,d,nn);
        }
        for(int i=1;i<=nn;i++) if(!dfn[i]) tarjan(i);
        for(int u=1;u<=nn;u++) for(auto &v: g1[u])
        {
            if(col[u]==col[v]) continue;
            g2[col[u]].push_back(col[v]);
            gr[col[v]].push_back(col[u]);
        }
        for(int i=1;i<=n;i++) w[col[i]]++;
        bool fl=false;
        int oldnn=nn;
        nn=ccnt;
        for(int i=1;i<=nn;i++)
        {
            if(w[i]<lim) continue;
            bool res=solve1(i);
            if(res) {fl=true;break;}
        }
        if(!fl && solve2()) fl=true;
        if(!fl) qout<<"NIE\n";
        else
        {
            qout<<"TAK\n";
            for(int i=1;i<=n;i++) qout<<ans[col[i]];
            qout<<'\n';
        }
        tot=top=ccnt=0;
        for(int i=1;i<=oldnn;i++)
        {
            g1[i].clear(),g2[i].clear(),gr[i].clear();
            w[i]=dfn[i]=low[i]=col[i]=0;
            vis[i]=false;
        }
    }
    return 0;
}
/*
2
1 3
1 1 2 2
1 2 3 3
1 1 3 3
1 3
1 1 2 2
2 2 3 3
3 3 1 1

*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 40428kb

input:

2
1 3
1 1 2 2
1 2 3 3
1 1 3 3
1 3
1 1 2 2
2 2 3 3
3 3 1 1

output:

TAK
RRF
NIE

result:

ok good!

Test #2:

score: 0
Accepted
time: 1821ms
memory: 102168kb

input:

10
33333 100000
28701 40192 93418 95143
95902 97908 78378 78461
36823 44196 22268 23996
23977 24786 33315 48829
83965 90411 4923 8445
20235 21177 32543 47454
29598 35414 72477 73049
2014 12632 42163 46466
64305 65518 98825 99552
32331 41625 92772 96224
26500 54122 76990 77126
18249 20335 31165 36080...

output:

NIE
NIE
NIE
NIE
NIE
NIE
NIE
NIE
NIE
NIE

result:

ok good!

Test #3:

score: 0
Accepted
time: 1714ms
memory: 134176kb

input:

10
33333 100000
15207 33614 66276 66276
97173 97173 67589 73960
19673 36626 65207 65207
89825 98169 27079 27079
56067 56966 7560 7560
18170 35477 18752 18752
32621 36748 34460 34460
61595 61700 14117 14117
32395 36710 9064 9064
13172 13172 1728 4640
40462 41878 47171 47171
76965 82414 5767 5767
9225...

output:

TAK
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF...

result:

ok good!

Test #4:

score: 0
Accepted
time: 1590ms
memory: 122004kb

input:

10
33333 100000
2646 2646 6430 6446
82226 82231 15128 15132
877 877 85831 88474
51389 79196 37573 37573
38030 38030 14248 14280
63032 68489 81074 81074
46468 46468 7403 7487
19864 20058 97979 97979
71640 71833 8558 8558
12121 12434 82481 82481
32901 32901 1899 2162
65312 77886 75969 75974
87983 8798...

output:

TAK
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFRRFFFFRFFRRFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF...

result:

ok good!

Test #5:

score: -100
Wrong Answer
time: 253ms
memory: 40508kb

input:

87005
1 3
1 1 2 2
1 2 3 3
1 1 3 3
1 3
1 1 2 2
2 2 3 3
3 3 1 1
1 1
1 3 2 3
1 2
1 1 2 2
2 2 1 1
1 2
1 3 1 1
1 1 1 3
4 20
3 5 6 12
4 5 7 11
1 1 2 2
3 4 7 12
3 5 10 10
3 5 8 8
4 4 9 11
4 4 7 7
1 1 9 10
3 4 6 9
3 5 11 12
3 3 7 9
3 5 2 2
4 5 2 2
1 1 7 11
1 1 10 10
3 5 7 8
4 4 2 2
1 1 2 2
4 5 8 10
4 12
11 ...

output:

TAK
RRF
NIE
TAK
RFF
TAK
FFR
NIE
TAK
RFRRRFFFFFFF
TAK
RFRFFFFFRFFR
NIE
TAK
RFFRRRFFFFFFFFR
TAK
FRRFRRFFFFFF
TAK
FFRRFRFFRFFF
TAK
FFFFFRFFFFFRRRR
TAK
RRRFFRFFFFFF
TAK
RRRRRFFFFFFFFFF
NIE
TAK
RFFFRRFFRFFF
NIE
TAK
RRFFFRRFF
NIE
TAK
FFFFFRRRF
TAK
RRRRFFFFFFFF
TAK
RRFFRFRFFFFFRFF
TAK
RRRFFRFFFFFF
NIE
TAK
...

result:

wrong answer zla odpowiedz!