답안 #424237

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
424237 2021-06-11T18:29:28 Z duality Arranging Tickets (JOI17_arranging_tickets) C++11
65 / 100
6000 ms 7004 KB
#define DEBUG 0

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

#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}

// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
    public:
        template<typename T>
        _Debug& operator,(T val) {
            cout << val << endl;
            return *this;
        }
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif

// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back

// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;

// ---------- END OF TEMPLATE ----------

int N,A[100000],B[100000],C[100000];
int num[200000];
pii order[100000];
int tree[1 << 19],lazy[1 << 19];
int build(int s,int e,int i) {
    if (s == e) {
        tree[i] = num[s],lazy[i] = 0;
        return 0;
    }

    int mid = (s+e) / 2;
    build(s,mid,2*i+1),build(mid+1,e,2*i+2);
    tree[i] = max(tree[2*i+1],tree[2*i+2]),lazy[i] = 0;
    return 0;
}
int prop(int s,int e,int i) {
    if (lazy[i] != 0) {
        tree[i] += lazy[i];
        if (s != e) lazy[2*i+1] += lazy[i],lazy[2*i+2] += lazy[i];
        lazy[i] = 0;
    }
    return 0;
}
int update(int s,int e,int as,int ae,int i,int num) {
    prop(s,e,i);
    if ((s > ae) || (e < as)) return 0;
    else if ((s >= as) && (e <= ae)) {
        lazy[i] += num;
        prop(s,e,i);
        return 0;
    }

    int mid = (s+e) / 2;
    update(s,mid,as,ae,2*i+1,num),update(mid+1,e,as,ae,2*i+2,num);
    tree[i] = max(tree[2*i+1],tree[2*i+2]);
    return 0;
}
int query(int s,int e,int qs,int qe,int i) {
    prop(s,e,i);
    if ((s > qe) || (e < qs)) return -1e9;
    else if ((s >= qs) && (e <= qe)) return tree[i];

    int mid = (s+e) / 2;
    return max(query(s,mid,qs,qe,2*i+1),query(mid+1,e,qs,qe,2*i+2));
}
int main() {
    int i;
    int M;
    LLI ans = 0;
    scanf("%d %d",&N,&M);
    for (i = 0; i < M; i++) {
        scanf("%d %d %d",&A[i],&B[i],&C[i]);
        if (!(C[i] & 1)) ans += C[i]/2,i--,M--;
        else {
            if (A[i] > B[i]) swap(A[i],B[i]);
        }
    }

    int j;
    int ans2 = 1e9;
    for (i = 0; i < 50; i++) {
        int x = rand() % N;
        fill(num,num+N,0);
        for (j = 0; j < M; j++) {
            A[j] = (A[j]+x) % N,B[j] = (B[j]+x) % N;
            if (A[j] > B[j]) swap(A[j],B[j]);
            num[A[j]]--,num[B[j]]++;
            order[j] = mp(B[j],j);
        }
        for (j = 1; j < N; j++) num[j] += num[j-1];
        build(0,N-1,0);
        int a = M;
        sort(order,order+M);
        for (j = 0; j < M; j++) {
            int u = order[j].second;
            if (query(0,N-1,A[u],B[u]-1,0) < -1) update(0,N-1,A[u],B[u]-1,0,2),a--;
        }
        ans2 = min(ans2,a);
    }
    printf("%lld\n",ans+ans2);

    return 0;
}

Compilation message

arranging_tickets.cpp: In function 'int main()':
arranging_tickets.cpp:107:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  107 |     scanf("%d %d",&N,&M);
      |     ~~~~~^~~~~~~~~~~~~~~
arranging_tickets.cpp:109:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  109 |         scanf("%d %d %d",&A[i],&B[i],&C[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 11 ms 336 KB Output is correct
17 Correct 8 ms 332 KB Output is correct
18 Correct 8 ms 340 KB Output is correct
19 Correct 8 ms 332 KB Output is correct
20 Correct 11 ms 344 KB Output is correct
21 Correct 8 ms 332 KB Output is correct
22 Correct 8 ms 340 KB Output is correct
23 Correct 10 ms 332 KB Output is correct
24 Correct 10 ms 340 KB Output is correct
25 Correct 7 ms 332 KB Output is correct
26 Correct 7 ms 284 KB Output is correct
27 Correct 8 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 11 ms 336 KB Output is correct
17 Correct 8 ms 332 KB Output is correct
18 Correct 8 ms 340 KB Output is correct
19 Correct 8 ms 332 KB Output is correct
20 Correct 11 ms 344 KB Output is correct
21 Correct 8 ms 332 KB Output is correct
22 Correct 8 ms 340 KB Output is correct
23 Correct 10 ms 332 KB Output is correct
24 Correct 10 ms 340 KB Output is correct
25 Correct 7 ms 332 KB Output is correct
26 Correct 7 ms 284 KB Output is correct
27 Correct 8 ms 332 KB Output is correct
28 Correct 116 ms 460 KB Output is correct
29 Correct 148 ms 460 KB Output is correct
30 Correct 109 ms 332 KB Output is correct
31 Correct 106 ms 448 KB Output is correct
32 Correct 103 ms 440 KB Output is correct
33 Correct 123 ms 440 KB Output is correct
34 Correct 103 ms 436 KB Output is correct
35 Correct 110 ms 460 KB Output is correct
36 Correct 113 ms 460 KB Output is correct
37 Correct 103 ms 440 KB Output is correct
38 Correct 126 ms 452 KB Output is correct
39 Correct 116 ms 452 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 11 ms 336 KB Output is correct
17 Correct 8 ms 332 KB Output is correct
18 Correct 8 ms 340 KB Output is correct
19 Correct 8 ms 332 KB Output is correct
20 Correct 11 ms 344 KB Output is correct
21 Correct 8 ms 332 KB Output is correct
22 Correct 8 ms 340 KB Output is correct
23 Correct 10 ms 332 KB Output is correct
24 Correct 10 ms 340 KB Output is correct
25 Correct 7 ms 332 KB Output is correct
26 Correct 7 ms 284 KB Output is correct
27 Correct 8 ms 332 KB Output is correct
28 Correct 116 ms 460 KB Output is correct
29 Correct 148 ms 460 KB Output is correct
30 Correct 109 ms 332 KB Output is correct
31 Correct 106 ms 448 KB Output is correct
32 Correct 103 ms 440 KB Output is correct
33 Correct 123 ms 440 KB Output is correct
34 Correct 103 ms 436 KB Output is correct
35 Correct 110 ms 460 KB Output is correct
36 Correct 113 ms 460 KB Output is correct
37 Correct 103 ms 440 KB Output is correct
38 Correct 126 ms 452 KB Output is correct
39 Correct 116 ms 452 KB Output is correct
40 Execution timed out 6045 ms 7004 KB Time limit exceeded
41 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 11 ms 336 KB Output is correct
17 Correct 8 ms 332 KB Output is correct
18 Correct 8 ms 340 KB Output is correct
19 Correct 8 ms 332 KB Output is correct
20 Correct 11 ms 344 KB Output is correct
21 Correct 8 ms 332 KB Output is correct
22 Correct 8 ms 340 KB Output is correct
23 Correct 10 ms 332 KB Output is correct
24 Correct 10 ms 340 KB Output is correct
25 Correct 7 ms 332 KB Output is correct
26 Correct 7 ms 284 KB Output is correct
27 Correct 8 ms 332 KB Output is correct
28 Correct 116 ms 460 KB Output is correct
29 Correct 148 ms 460 KB Output is correct
30 Correct 109 ms 332 KB Output is correct
31 Correct 106 ms 448 KB Output is correct
32 Correct 103 ms 440 KB Output is correct
33 Correct 123 ms 440 KB Output is correct
34 Correct 103 ms 436 KB Output is correct
35 Correct 110 ms 460 KB Output is correct
36 Correct 113 ms 460 KB Output is correct
37 Correct 103 ms 440 KB Output is correct
38 Correct 126 ms 452 KB Output is correct
39 Correct 116 ms 452 KB Output is correct
40 Execution timed out 6045 ms 7004 KB Time limit exceeded
41 Halted 0 ms 0 KB -