QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#557051#4688. Window ManagerAllSolvedin1557WA 1ms3840kbC++177.5kb2024-09-11 01:27:362024-09-11 01:27:36

Judging History

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

  • [2024-09-11 01:27:36]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3840kb
  • [2024-09-11 01:27:36]
  • 提交

answer

#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef long double ld;

struct dat{
    ll x,y,w,h,time;
    bool in(ll a,ll b) { return (x<=a&&a<x+w&&y<=b&&b<y+h); }
    bool inter(dat d) { return d.in(x,y)||d.in(x,y+h)||d.in(x+w,y)||d.in(x+w,y+h)||in(d.x,d.y)||in(d.x,d.y+d.h)||in(d.x+d.w,d.y)||in(d.x+d.w,d.y+d.h); }
    bool inc(dat d) { return in(d.x,d.y)&&in(d.x,d.y+d.h-1)&&in(d.x+d.w-1,d.y)&&in(d.x+d.w-1,d.y+d.h-1); }
    bool interx(dat d) { return (y<d.y+d.h&&d.y<y+h); }
    bool intery(dat d) { return (x<d.x+d.w&&d.x<x+w); }
    bool operator==(const dat &d)
    {
        return x==d.x&&y==d.y&&h==d.h&&w==d.w;
    }
};

vector<dat>W;

void notfit(ll cnt, string &comm)
{ cout<<"Command "<<cnt<<": "<<comm<<" - window does not fit\n"; }

void notpos(ll cnt, string &comm)
{ cout<<"Command "<<cnt<<": "<<comm<<" - no window at given position\n"; }

void notmov(ll cnt, string &comm, ll real, ll fact)
{ cout<<"Command "<<cnt<<": "<<comm<<" - moved "<<real<<" instead of "<<fact<<"\n"; }

int main()
{
    ios::sync_with_stdio(0); cin.tie(0);
    ll X,Y,cnt=0; cin>>X>>Y;
    bool debug = 0;
    dat S={0,0,X,Y};
    while(1)
    {
        string s;
        cin>>s;
        cnt++;

        if(cin.eof()) break;
        if(s=="OPEN")
        {
            ll x,y,w,h; cin>>x>>y>>w>>h;
            dat now={x,y,w,h,cnt};
            if(!S.inc(now))
            {
                notfit(cnt,s);
                continue;
            }
            bool flag=1;
            for(auto d:W)
                if(d.inter(now)) flag=0;
            if(flag)
                W.push_back(now);
            else notfit(cnt,s);
        }
        if(s=="RESIZE")
        {
            ll x,y,w,h; cin>>x>>y>>w>>h;

            ll ex=-1;
            for(int i=0;i<W.size();i++) if(W[i].in(x,y)) ex=i;
            if(ex==-1)
            {
                notpos(cnt,s);
                continue;
            }
            dat prv=W[ex];
            W.erase(W.begin()+ex);
            dat now=prv; now.w=w; now.h=h;

            if(!S.inc(now))
            {
                W.push_back(prv);
                notfit(cnt,s);
                continue;
            }
            bool flag=1;
            for(auto d:W)
                if(d.inter(now)) flag=0;
            if(flag)
                W.push_back(now);
            else W.push_back(prv), notfit(cnt,s);
        }
        if(s=="CLOSE")
        {
            ll x,y; cin>>x>>y;
            ll ex=-1;
            for(int i=0;i<W.size();i++) if(W[i].in(x,y)) ex=i;
            if(ex==-1)
            {
                notpos(cnt,s);
                continue;
            }
            W.erase(W.begin()+ex);
        }
        if(s=="MOVE")
        {
            ll x,y,dx,dy; cin>>x>>y>>dx>>dy;
            ll ex=-1;
            for(int i=0;i<W.size();i++) if(W[i].in(x,y)) ex=i;
            if(ex==-1)
            {
                notpos(cnt,s);
                continue;
            }
            dat now=W[ex];
            if(dx>0)
            {
                sort(W.begin(),W.end(),[](dat a,dat b){ return a.x<b.x; });
                int pos;
                for(int i=0;i<W.size();i++) if(W[i]==now) pos=i;
                vector<ll>dist(W.size(),0);
                ll over=0;
                for(ll i=pos;i<W.size();i++)
                {
                    if(i==pos) dist[i]=dx;
                    else
                    {
                        for(ll j=pos;j<i;j++)
                        {
                            if(W[i].interx(W[j]))
                                dist[i]=max(dist[i],dist[j]-abs(W[i].x-W[j].x-W[j].w));
                        }
                    }
                    over=max(over,dist[i]-(X-W[i].x-W[i].w));
                }
                if(over>0) notmov(cnt,s,dx-over,dx);
                for(ll i=pos;i<W.size();i++)
                {
                    W[i].x+=max(0LL,dist[i]-over);
                }
            }
            if(dx<0)
            {
                sort(W.begin(),W.end(),[](dat a,dat b){ return a.x>b.x; });
                dx*=-1;
                int pos;
                for(int i=0;i<W.size();i++) if(W[i]==now) pos=i;
                vector<ll>dist(W.size(),0);
                ll over=0;
                for(ll i=pos;i<W.size();i++)
                {
                    if(i==pos) dist[i]=dx;
                    else
                    {
                        for(ll j=pos;j<i;j++)
                        {
                            if(W[i].interx(W[j]))
                                dist[i]=max(dist[i],dist[j]-abs(W[i].x-W[j].x+W[i].w));
                        }
                    }
                    over=max(over,dist[i]-(W[i].x));
                }
                if(over>0) notmov(cnt,s,dx-over,dx);
                for(ll i=pos;i<W.size();i++)
                {
                    W[i].x-=max(0LL,dist[i]-over);
                }
            }
            if(dy>0)
            {
                sort(W.begin(),W.end(),[](dat a,dat b){ return a.y<b.y; });
                int pos;
                for(int i=0;i<W.size();i++) if(W[i]==now) pos=i;
                vector<ll>dist(W.size(),0);
                ll over=0;
                for(ll i=pos;i<W.size();i++)
                {
                    if(i==pos) dist[i]=dy;
                    else
                    {
                        for(ll j=pos;j<i;j++)
                        {
                            if(W[i].intery(W[j]))
                                dist[i]=max(dist[i],dist[j]-abs(W[i].y-W[j].y-W[j].h));
                        }
                    }
                    over=max(over,dist[i]-(Y-W[i].y-W[i].h));
                }
                if(over>0) notmov(cnt,s,dy-over,dy);
                for(ll i=pos;i<W.size();i++)
                {
                    W[i].y+=max(0LL,dist[i]-over);
                }
            }
            if(dy<0)
            {
                sort(W.begin(),W.end(),[](dat a,dat b){ return a.y>b.y; });
                dy*=-1;
                int pos;
                for(int i=0;i<W.size();i++) if(W[i]==now) pos=i;
                if(debug)
                {
                    cout<<cnt<<'\n';
                    cout<<"-------\n";
                    for(auto [x,y,w,h,t]:W) cout<<x<<' '<<y<<' '<<w<<' '<<h<<' '<<t<<'\n';
                    cout<<"-------\n";
                }
                vector<ll>dist(W.size(),0);
                ll over=0;
                for(ll i=pos;i<W.size();i++)
                {
                    if(i==pos) dist[i]=dy;
                    else
                    {
                        for(ll j=pos;j<i;j++)
                        {
                            if(W[i].intery(W[j]))
                                dist[i]=max(dist[i],dist[j]-abs(W[i].y-W[j].y+W[i].h));
                        }
                    }
                    over=max(over,dist[i]-(W[i].y));
                }
                if(over>0) notmov(cnt,s,dy-over,dy);
                for(ll i=pos;i<W.size();i++)
                {
                    W[i].y-=max(0LL,dist[i]-over);
                }
            }
        }

    }
    sort(W.begin(),W.end(),[](dat a,dat b){ return a.time<b.time; });
    cout<<W.size()<<" window(s):\n";
    for(auto [x,y,w,h,t]:W) cout<<x<<' '<<y<<' '<<w<<' '<<h<<'\n';

    return 0;
}



Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

320 200
OPEN 50 50 10 10
OPEN 70 55 10 10
OPEN 90 50 10 10
RESIZE 55 55 40 40
RESIZE 55 55 15 15
MOVE 55 55 40 0
CLOSE 55 55
CLOSE 110 60
MOVE 95 55 0 -100

output:

Command 4: RESIZE - window does not fit
Command 7: CLOSE - no window at given position
Command 9: MOVE - moved 50 instead of 100
2 window(s):
90 0 15 15
115 50 10 10

result:

ok 6 lines

Test #2:

score: 0
Accepted
time: 0ms
memory: 3772kb

input:

10 10
OPEN 0 0 8 8
MOVE 0 0 5 0

output:

Command 2: MOVE - moved 2 instead of 5
1 window(s):
2 0 8 8

result:

ok 3 lines

Test #3:

score: 0
Accepted
time: 0ms
memory: 3500kb

input:

10 10
OPEN 2 2 8 8
MOVE 3 3 -5 0

output:

Command 2: MOVE - moved 2 instead of 5
1 window(s):
0 2 8 8

result:

ok 3 lines

Test #4:

score: 0
Accepted
time: 1ms
memory: 3552kb

input:

10 10
OPEN 2 2 8 8
MOVE 3 3 0 -5

output:

Command 2: MOVE - moved 2 instead of 5
1 window(s):
2 0 8 8

result:

ok 3 lines

Test #5:

score: 0
Accepted
time: 0ms
memory: 3568kb

input:

10 10
OPEN 0 0 8 8
MOVE 0 0 0 5

output:

Command 2: MOVE - moved 2 instead of 5
1 window(s):
0 2 8 8

result:

ok 3 lines

Test #6:

score: 0
Accepted
time: 0ms
memory: 3576kb

input:

6000 6000
OPEN 5000 5000 5 5
OPEN 5000 4990 5 5
OPEN 5000 4980 5 5
OPEN 5000 4970 5 5
OPEN 5000 4960 5 5
OPEN 5000 4950 5 5
OPEN 5000 4940 5 5
OPEN 5000 4930 5 5
OPEN 5000 4920 5 5
OPEN 5000 4910 5 5
OPEN 5000 4900 5 5
OPEN 5000 4890 5 5
OPEN 5000 4880 5 5
OPEN 5000 4870 5 5
OPEN 5000 4860 5 5
OPEN ...

output:

200 window(s):
5000 1000 5 5
5000 995 5 5
5000 990 5 5
5000 985 5 5
5000 980 5 5
5000 975 5 5
5000 970 5 5
5000 965 5 5
5000 960 5 5
5000 955 5 5
5000 950 5 5
5000 945 5 5
5000 940 5 5
5000 935 5 5
5000 930 5 5
5000 925 5 5
5000 920 5 5
5000 915 5 5
5000 910 5 5
5000 905 5 5
5000 900 5 5
5000 895 5 ...

result:

ok 201 lines

Test #7:

score: -100
Wrong Answer
time: 0ms
memory: 3840kb

input:

1000 1000
OPEN 0 0 10 10
OPEN 10 0 10 10
OPEN 20 0 10 10
OPEN 0 10 10 10
OPEN 10 10 10 10
OPEN 20 10 10 10
OPEN 0 20 10 10
OPEN 10 20 10 10
OPEN 20 20 10 10
CLOSE 19 19
CLOSE 20 20
CLOSE 0 10

output:

Command 2: OPEN - window does not fit
Command 4: OPEN - window does not fit
Command 5: OPEN - window does not fit
Command 6: OPEN - window does not fit
Command 8: OPEN - window does not fit
Command 10: CLOSE - no window at given position
Command 12: CLOSE - no window at given position
3 window(s):
0...

result:

wrong answer 1st lines differ - expected: '6 window(s):', found: 'Command 2: OPEN - window does not fit'