QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#628751 | #7725. Just Sum Two Numbers | PlentyOfPenalty# | WA | 6ms | 6016kb | C++20 | 4.5kb | 2024-10-10 22:02:56 | 2024-10-10 22:02:57 |
Judging History
answer
#include <bits/stdc++.h>
#define sz(x) ((int)(x).size())
#define all(x) begin(x), end(x)
#ifdef memset0
#define log(...) fprintf(stderr, __VA_ARGS__)
#else
#define endl '\n'
#define log(...) (void(0))
#endif
using namespace std;
using ll = long long;
using lf = long double;
using pii = pair<int, int>;
using ull = unsigned long long;
template <class T> struct Point {
using P = Point;
T x, y;
explicit Point(T x = 0, T y = 0) : x(x), y(y) {}
bool operator<(P p) const { return tie(x, y) < tie(p.x, p.y); }
bool operator==(P p) const { return tie(x, y) == tie(p.x, p.y); }
P operator-(P p) const { return P(x - p.x, y - p.y); }
T dot(P p) const { return x * p.x + y * p.y; }
T cross(P p) const { return x * p.y - y * p.x; }
T cross(P a, P b) const { return (a - *this).cross(b - *this); }
T dist2() const { return x * x + y * y; }
double dist() const { return sqrt(dist2()); }
};
using pt = Point<ll>;
vector<pt> convexHull(vector<pt> pts) {
if (sz(pts) <= 1) return pts;
sort(all(pts));
vector<pt> h(sz(pts) + 1);
int s = 0, t = 0;
for (int it = 2; it--; s = --t, reverse(all(pts)))
for (pt p : pts) {
while (t >= s + 2 && h[t - 2].cross(h[t - 1], p) <= 0) t--;
h[t++] = p;
}
return {h.begin(), h.begin() + t - (t == 2 && h[0] == h[1])};
}
pair<pt, pt> hullIiameter(vector<pt> S) {
int n = sz(S), j = n < 2 ? 0 : 1;
pair<ll, pair<pt, pt>> res({0, {S[0], S[0]}});
for (int i = 0; i < j; i++)
for (;; j = (j + 1) % n) {
res = max(res, {(S[i] - S[j]).dist2(), {S[i], S[j]}});
if ((S[(j + 1) % n] - S[j]).cross(S[i + 1] - S[i]) >= 0) break;
}
return res.second;
}
double polygonArea(const vector<pt> &v) {
ll a = v.back().cross(v[0]);
for (int i = 0; i + 1 < sz(v); i++) {
a += v[i].cross(v[i + 1]);
}
return abs(a / 2.0);
}
double lineDist(pt a, pt b, pt p) { return (double)(b - a).cross(p - a) / (b - a).dist(); }
const int N = 1e6 + 9, M = 1e3 + 9;
const int nxt[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
int n, m, ql, qr;
bool a[M][M], vis[M][M];
string buffer;
pair<int, int> q[N];
struct Pattern {
vector<pii> a;
vector<pt> b, cov;
double x, y;
pair<pt, pt> s;
int num;
bool operator<(const Pattern &rhs) const { return y < rhs.y; }
};
vector<Pattern> vec;
int main() {
#ifdef memset0
freopen("J.in", "r", stdin);
#endif
cin.tie(0)->sync_with_stdio(0);
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> buffer;
for (int j = 1; j <= m; j++) {
a[i][j] = buffer[j - 1] == '#';
}
}
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
if (a[i][j] && !vis[i][j]) {
q[ql = qr = 1] = {i, j}, vis[i][j] = 1;
while (ql <= qr) {
auto u = q[ql++];
for (int k = 0; k < 4; k++) {
int vx = u.first + nxt[k][0];
int vy = u.second + nxt[k][1];
if (a[vx][vy] && !vis[vx][vy]) {
q[++qr] = {vx, vy}, vis[vx][vy] = 1;
}
}
}
vec.resize(vec.size() + 1);
auto &cur = vec.back();
cur.a = vector<pii>(q + 1, q + qr + 1);
for (const auto &[x, y] : cur.a) {
cur.b.emplace_back(x - 1, y - 1);
cur.b.emplace_back(x - 1, y);
cur.b.emplace_back(x, y - 1);
cur.b.emplace_back(x, y);
}
sort(all(cur.b));
cur.b.erase(unique(all(cur.b)), cur.b.end());
cur.cov = convexHull(cur.b);
cur.s = hullIiameter(cur.cov);
cur.x = ((double)cur.s.first.x + cur.s.second.x) / 2;
cur.y = ((double)cur.s.first.y + cur.s.second.y) / 2;
}
sort(all(vec));
for (auto &cur : vec) {
double area = polygonArea(cur.cov);
log("cells %d area = %.2lf\n", sz(cur.a), area);
if (cur.a.size() > 0.8 * area) {
cur.num = 1;
} else {
double w = (cur.s.first - cur.s.second).dist();
double h = 0;
for (const auto &p : cur.b) {
h = max(h, lineDist(cur.s.first, cur.s.second, p));
}
h *= 2;
if (h / w > 0.5) {
cur.num = 0;
} else if (h / w > 0.05) {
cur.num = 5;
} else {
cur.num = 1;
}
}
log(">> num = %d\n", cur.num);
}
int ans = 0;
bool have_plus = false;
for (int i = 0; i < sz(vec); i++) {
if (vec[i].num == 0) {
if (have_plus) {
vec[i].num = 5;
}
have_plus = true;
}
ans += vec[i].num;
}
cout << ans << endl;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3936kb
input:
100 354 .......................................................................................................................................................................................................................................................................................................
output:
17
result:
ok 1 number(s): "17"
Test #2:
score: 0
Accepted
time: 3ms
memory: 4356kb
input:
135 269 ............................................................................................................................................................................................................................................................................. .........................
output:
14
result:
ok 1 number(s): "14"
Test #3:
score: 0
Accepted
time: 3ms
memory: 6016kb
input:
294 451 .......................................................................................................................................................................................................................................................................................................
output:
18
result:
ok 1 number(s): "18"
Test #4:
score: 0
Accepted
time: 5ms
memory: 5948kb
input:
234 701 .......................................................................................................................................................................................................................................................................................................
output:
32
result:
ok 1 number(s): "32"
Test #5:
score: -100
Wrong Answer
time: 6ms
memory: 5932kb
input:
888 585 .......................................................................................................................................................................................................................................................................................................
output:
57
result:
wrong answer 1st numbers differ - expected: '49', found: '57'