QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#226731#7583. Faraway8BQube#AC ✓40ms3480kbC++202.0kb2023-10-26 14:54:372023-10-26 14:54:37

Judging History

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

  • [2023-10-26 14:54:37]
  • 评测
  • 测评结果:AC
  • 用时:40ms
  • 内存:3480kb
  • [2023-10-26 14:54:37]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define X first
#define Y second
#define pb push_back
#define SZ(a) ((int)a.size())
#define ALL(v) v.begin(), v.end()

const int C = 60;

ll floor(ll a, ll b) {
    return a / b - (a % b && (a < 0) ^ (b < 0));
}
ll ceil(ll a, ll b) {
    return a / b + (a % b && (a < 0) ^ (b > 0));
}

ll num(ll d, ll l, ll r) {
    ll tl = ceil(l - d, 60) * 60 + d;
    ll tr = floor(r - d, 60) * 60 + d;
    if (tl > tr) return 0;
    return (tr - tl) / 60 + 1;
}

struct node {
    int x, y, k, t;
} arr[15];

void solve() {
    int n, m;
    cin >> n >> m;
    vector<int> xval({0, m + 1}), yval({0, m + 1});
    for (int i = 1; i <= n; ++i) {
        cin >> arr[i].x >> arr[i].y >> arr[i].k >> arr[i].t;
        xval.pb(arr[i].x);
        yval.pb(arr[i].y);
    }
    sort(ALL(xval)), xval.resize(unique(ALL(xval)) - xval.begin());
    sort(ALL(yval)), yval.resize(unique(ALL(yval)) - yval.begin());

    auto check = [&](int x, int y, int cx, int cy) {
        for (int i = 1; i <= n; ++i) {
            ll val = 0;
            if (cx < arr[i].x) val += arr[i].x - x;
            else val += x - arr[i].x;
            if (cy < arr[i].y) val += arr[i].y - y;
            else val += y - arr[i].y;
            if ((val % arr[i].k + arr[i].k) % arr[i].k != arr[i].t)
                return false;
        }
        return true;
    };

    ll ans = 0;
    for (int x = 0; x < 60; ++x)
        for (int y = 0; y < 60; ++y)
            for (int xi = 0; xi + 1 < SZ(xval); ++xi)
                for (int yi = 0; yi + 1 < SZ(yval); ++yi) {
                    if (check(x, y, xval[xi], yval[yi])) {
                        ans += num(x, xval[xi], xval[xi + 1] - 1) * num(y, yval[yi], yval[yi + 1] - 1); 
                    }
                }
    cout << ans << "\n";
}

int main() {
    ios::sync_with_stdio(0), cin.tie(0);
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3480kb

input:

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

output:

10
0

result:

ok 2 number(s): "10 0"

Test #2:

score: 0
Accepted
time: 40ms
memory: 3412kb

input:

10
10 950006
879210 618398 2 0
413993 805537 5 0
614389 782151 5 4
616385 454674 4 2
6020 332147 5 0
77932 43110 4 1
143614 196643 4 0
937161 934707 4 1
318567 789911 4 0
194658 555381 5 3
10 967857178
8983267 44864625 3 2
141087113 359274718 2 1
909006720 262061158 3 0
840340929 715591525 3 2
76531...

output:

0
0
0
116256265
43298776834
1839945977784
820599567890959
19922821864719464
50544306663055
64150016306836

result:

ok 10 numbers