QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#814391#9879. ReTravelucup-team2796#WA 1525ms5292kbC++232.0kb2024-12-14 17:12:172024-12-14 17:12:17

Judging History

This is the latest submission verdict.

  • [2024-12-14 17:12:17]
  • Judged
  • Verdict: WA
  • Time: 1525ms
  • Memory: 5292kb
  • [2024-12-14 17:12:17]
  • Submitted

answer

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

#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) sort(ALL(v)), (v).erase(unique(ALL(v)), (v).end())
#define SZ(v) (int)v.size()
#define MIN(v) *min_element(ALL(v))
#define MAX(v) *max_element(ALL(v))
#define LB(v, x) int(lower_bound(ALL(v), (x)) - (v).begin())
#define UB(v, x) int(upper_bound(ALL(v), (x)) - (v).begin())

using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long;
using i128 = __int128_t;
using u128 = __uint128_t;
const int inf = 0x3fffffff;
const ll INF = 0x1fffffffffffffff;

template <typename T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

ll dist(vector<pair<ll, ll>> XY, ll i, ll j){
    auto [Xi, Yi] = XY[i];
    auto [Xj, Yj] = XY[j];
    return abs(Xi - Xj) + abs(Yi - Yj);
}

ll waste(vector<pair<ll, ll>> XY, ll i, ll j, ll k){
    auto [Xi, Yi] = XY[i];
    auto [Xj, Yj] = XY[j];
    auto [Xk, Yk] = XY[k];
    ll ret = 0;
    if ((Xj - Xi) * (Xk - Xi) > 0){
        ret += min(abs(Xj - Xi), abs(Xk - Xi));}
    if ((Yj - Yi) * (Yk - Yi) > 0){
        ret += min(abs(Yj - Yi), abs(Yk - Yi));}
    return ret;
}   

int main(){
    int N;
    cin >> N;
    vector<pair<ll, ll>> XY;
    XY.emplace_back(0, 0);
    rep(i, 0, N){
        ll x, y;
        cin >> x >> y;
        XY.emplace_back(x, y);
    }
    ll INF = 1e18;
    vector<vector<ll>> dp(N+1, vector<ll>(N+1, INF));
    rep(i, 1, N+1){
        dp[i][i] = dist(XY, 0, i);
    }
    rep(length, 1, N){
        rep(i, 1, N-length+1){
            ll j = i + length;
            rep(k, i, j){
                chmin(dp[i][j], dp[i][k] + dp[k+1][j] - waste(XY, 0, i, j));
            }
        }
    }
    cout << dp[1][N] << endl;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2
3 3
1 2

output:

6

result:

ok "6"

Test #2:

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

input:

3
2 2
3 3
1 3

output:

7

result:

ok "7"

Test #3:

score: -100
Wrong Answer
time: 1525ms
memory: 5292kb

input:

500
906691059 413653999
813847339 955892128
451585301 43469773
278009742 548977048
521760889 434794718
985946604 841597326
891047768 325679554
511742081 384452587
626401695 957413342
975078788 234551094
541903389 149544006
302621084 150050891
811538590 101823753
663968655 858351976
268979133 9768326...

output:

3811588004

result:

wrong answer 1st words differ - expected: '202616034783', found: '3811588004'