QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#384106#4676. Amalgamated ArtichokesEnergy_is_not_over#WA 1ms3864kbC++173.3kb2024-04-09 20:46:362024-04-09 20:46:36

Judging History

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

  • [2024-04-09 20:46:36]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3864kb
  • [2024-04-09 20:46:36]
  • 提交

answer

//
// Stvoreno ENERGom o 09.04.24. 14:23:51
//

#include<bits/stdc++.h>

#define all(a) a.begin(),a.end()
#define len(a) (int)(a.size())
#define mp make_pair
#define MP make_pair
#define pb push_back
#define PB push_back
#define F first
#define fir first
#define S second
#define sec second

using namespace std;

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

#ifdef Energy
#define DEBUG for (int ____DEBUG=1;____DEBUG;____DEBUG=0)

template<class ...Ts>
auto &PRNT(Ts ...ts) { return ((cerr << ts << " "), ...); }

#define LOG(...) PRNT(#__VA_ARGS__" ::",__VA_ARGS__)<<endl
#else
#define DEBUG while(0)
#define LOG(...)
#endif

const int max_n = -1, inf = 1000111222;

struct rect {
    ll x, y, w, h;
};

vector<rect> v;
ll W, H;

bool in_bound(rect r) {
    return r.x >= 0 && r.y >= 0 && r.x + r.w - 1 < W && r.y + r.h - 1 < H;
}

bool inter_x(rect a, rect b) {
    return !(a.x > b.x + b.w - 1 || b.x > a.x + a.w - 1);
}

bool inter_y(rect a, rect b) {
    return !(a.y > b.y + b.h - 1 || b.y > a.y + a.h - 1);
}

bool inter(rect a, rect b) {
    return inter_x(a, b) && inter_y(a, b);
}

bool belongs(rect r, int x, int y) {
    return x >= r.x && x < r.x + r.w && y >= r.y && y < r.y + r.h;
}

int get_by_pos(int x, int y) {
    for (int i = 0; i < v.size(); ++i) {
        if (belongs(v[i], x, y)) {
            return i;
        }
    }
    return -1;
}

bool try_open(rect r) {
    if (!in_bound(r)) {
        return 0;
    }
    for (rect x : v) {
        if (inter(r, x)) {
            return 0;
        }
    }
    v.PB(r);
    return true;
}

int main() {
//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> W >> H;
    string cmd;
    int I = 0;
    while(cin >> cmd) {
        ++I;
        if (cmd == "OPEN") {
            rect r;
            cin >> r.x >> r.y >> r.w >> r.h;
            if (!try_open(r)) {
                cout << "Command " << I << ": " << "OPEN - window does not fit" << endl;
            }
            continue;
        }
        if (cmd == "CLOSE") {
            ll x, y;
            cin >> x >> y;
            int ind = get_by_pos(x, y);
            if (ind == -1) {
                cout << "Command " << I << ": " << "CLOSE - no window at given position" << endl;
            } else {
                v.erase(v.begin() + ind);
            }
            continue;
        }
        if (cmd == "RESIZE") {
            int x, y, nw, nh;
            cin >> x >> y >> nw >> nh;
            int ind = get_by_pos(x, y);
            if (ind == -1) {
                cout << "Command " << I << ": " << "RESIZE - no window at given position" << endl;
                continue;
            }
            rect was = v[ind];
            v.erase(v.begin() + ind);
            rect newr = was;
            newr.w = nw;
            newr.h = nh;
            if (!try_open(newr)) {
                cout << "Command " << I << ": " << "RESIZE - window does not fit" << endl;
                v.push_back(was);
            }
            continue;
        }
        if (cmd == "MOVE") {
            int x, y, dx, dy;
            cin >> x >> y >> dx >> dy;
        }
    }

    exit(0);
}

詳細信息

Test #1:

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

input:

42 1 23 4 8 10

output:


result:

wrong output format Unexpected end of file - double expected