Submission #77664

# Submission time Handle Problem Language Result Execution time Memory
77664 2018-09-29T16:05:08 Z duality ICC (CEOI16_icc) C++11
100 / 100
177 ms 1212 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 ----------
#include "icc.h"

vi sets[100];
int A[100],B[100];
void run(int N) {
    int i,j,k,l;
    for (i = 0; i < N; i++) sets[i].pb(i);
    for (i = 0; i < N-1; i++) {
        int L = N-i,la,lb;
        for (j = 0; (1 << j) < L; j++) {
            la = lb = 0;
            for (k = 0; k < L; k++) {
                if (k & (1 << j)) {
                    for (l = 0; l < sets[k].size(); l++) A[la++] = sets[k][l]+1;
                }
                else {
                    for (l = 0; l < sets[k].size(); l++) B[lb++] = sets[k][l]+1;
                }
            }
            if (query(la,lb,A,B)) break;
        }
        int l = 1,r = lb;
        while (l < r) {
            int m = (l+r) / 2;
            if (query(la,m,A,B)) r = m;
            else l = m+1;
        }
        int x = B[l-1];
        l = 1,r = la;
        while (l < r) {
            int m = (l+r) / 2;
            if (query(m,lb,A,B)) r = m;
            else l = m+1;
        }
        int y = A[l-1];
        setRoad(x,y);
        for (j = 0; j < L; j++) {
            for (k = 0; k < sets[j].size(); k++) {
                if (sets[j][k]+1 == x) {
                    x = j;
                    break;
                }
            }
            if (k < sets[j].size()) break;
        }
        for (j = 0; j < L; j++) {
            for (k = 0; k < sets[j].size(); k++) {
                if (sets[j][k]+1 == y) {
                    y = j;
                    break;
                }
            }
            if (k < sets[j].size()) break;
        }
        if (x > y) swap(x,y);
        for (j = 0; j < sets[y].size(); j++) sets[x].pb(sets[y][j]);
        sets[y].clear();
        if (y != L-1) {
            for (j = 0; j < sets[L-1].size(); j++) sets[y].pb(sets[L-1][j]);
        }
    }
}

Compilation message

icc.cpp: In function 'void run(int)':
icc.cpp:70:35: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                     for (l = 0; l < sets[k].size(); l++) A[la++] = sets[k][l]+1;
                                 ~~^~~~~~~~~~~~~~~~
icc.cpp:73:35: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                     for (l = 0; l < sets[k].size(); l++) B[lb++] = sets[k][l]+1;
                                 ~~^~~~~~~~~~~~~~~~
icc.cpp:94:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for (k = 0; k < sets[j].size(); k++) {
                         ~~^~~~~~~~~~~~~~~~
icc.cpp:100:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             if (k < sets[j].size()) break;
                 ~~^~~~~~~~~~~~~~~~
icc.cpp:103:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for (k = 0; k < sets[j].size(); k++) {
                         ~~^~~~~~~~~~~~~~~~
icc.cpp:109:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             if (k < sets[j].size()) break;
                 ~~^~~~~~~~~~~~~~~~
icc.cpp:112:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (j = 0; j < sets[y].size(); j++) sets[x].pb(sets[y][j]);
                     ~~^~~~~~~~~~~~~~~~
icc.cpp:115:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for (j = 0; j < sets[L-1].size(); j++) sets[y].pb(sets[L-1][j]);
                         ~~^~~~~~~~~~~~~~~~~~
icc.cpp:88:22: warning: 'lb' may be used uninitialized in this function [-Wmaybe-uninitialized]
             if (query(m,lb,A,B)) r = m;
                 ~~~~~^~~~~~~~~~
icc.cpp:81:22: warning: 'la' may be used uninitialized in this function [-Wmaybe-uninitialized]
             if (query(la,m,A,B)) r = m;
                 ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 9 ms 504 KB Ok! 94 queries used.
2 Correct 8 ms 644 KB Ok! 100 queries used.
# Verdict Execution time Memory Grader output
1 Correct 39 ms 644 KB Ok! 529 queries used.
2 Correct 48 ms 732 KB Ok! 647 queries used.
3 Correct 48 ms 808 KB Ok! 646 queries used.
# Verdict Execution time Memory Grader output
1 Correct 135 ms 956 KB Ok! 1379 queries used.
2 Correct 150 ms 956 KB Ok! 1595 queries used.
3 Correct 137 ms 956 KB Ok! 1594 queries used.
4 Correct 136 ms 976 KB Ok! 1496 queries used.
# Verdict Execution time Memory Grader output
1 Correct 135 ms 1048 KB Ok! 1420 queries used.
2 Correct 163 ms 1068 KB Ok! 1406 queries used.
3 Correct 146 ms 1148 KB Ok! 1540 queries used.
4 Correct 130 ms 1212 KB Ok! 1413 queries used.
# Verdict Execution time Memory Grader output
1 Correct 147 ms 1212 KB Ok! 1555 queries used.
2 Correct 177 ms 1212 KB Ok! 1582 queries used.
3 Correct 152 ms 1212 KB Ok! 1634 queries used.
4 Correct 148 ms 1212 KB Ok! 1559 queries used.
5 Correct 135 ms 1212 KB Ok! 1430 queries used.
6 Correct 145 ms 1212 KB Ok! 1552 queries used.
# Verdict Execution time Memory Grader output
1 Correct 145 ms 1212 KB Ok! 1599 queries used.
2 Correct 176 ms 1212 KB Ok! 1604 queries used.