Submission #255532

# Submission time Handle Problem Language Result Execution time Memory
255532 2020-08-01T07:52:19 Z davitmarg Mechanical Doll (IOI18_doll) C++17
100 / 100
179 ms 11656 KB
/*
DavitMarg
In a honky-tonk,
Down in Mexico
*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <stack>
#include <cassert>
#include <iterator>
#include <fstream>
#define mod 1000000007ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(), v.end()
#define fastIO ios::sync_with_stdio(false); cin.tie(0)
using namespace std;

const int N = 200005;

#ifndef  death
#include "doll.h"
#endif // ! death

#ifdef death
void answer(vector<int> c, vector<int> x, vector<int> y)
{
    cout << "!!" << x.size() << "!!" << endl;
    for (int i = 0; i < c.size(); i++)
        cout << c[i] << " ";
    cout << endl;
    for (int i = 0; i < x.size(); i++)
        cout << x[i] << " : " << y[i] << endl;
}
#endif

int n, k,ind[N+N+N];
vector<int> p, X, Y,nxt;

int add()
{
    k++;
    X.push_back(0);
    Y.push_back(0);
    return k;
}

int han = 0;

int inv(int x, int d)
{
    int res = 0;
    for (int i = 0; i < d; i++)
        if ((1 << i) & x)
            res += (1 << (d - 1 - i));
    return res;
}

void build(int st,int d, int c, int x)
{
    int v = k;
    if (c)
    {
        int x2 = x + (1 << (d + c + 1)) - (1 << (d + 1));
        if (inv(x2, c + d + 1) < han)
            X[v - 1] = -st;
        else
        {
            X[v - 1] = -add();
            build(st, d + 1, c - 1, x);
        }

        x += (1 << d);

        Y[v - 1] = -add();
        build(st, d + 1, c - 1, x);
    }
    else
    {
        int x1 = x;
        int x2 = x + (1 << d);
        if (inv(x1, c + d + 1) >= han)
            X[v - 1] = p[ind[x1]];
        else
            X[v - 1] = -st;

        if (inv(x2, c + d + 1) >= han)
            Y[v - 1] = p[ind[x2]];
        else
            Y[v - 1] = -st;
    }
}

void solve()
{
    add();
    for (int i = 0; i < 30; i++)
        if ((1 << i) >= p.size())
        {
            han = (1 << i) - p.size();
            vector<int> id;
            for (int j = han; j < (1 << i); j++)
                id.push_back(inv(j, i));
            sort(all(id));
            for (int j = 0; j < id.size(); j++)
                ind[id[j]] = j;
            build(k, 0, i-1, 0);
            break;
        }
}

void create_circuit(int M, vector<int> A)
{
    n = M;
    p = A;
    p.PB(0);
    nxt.resize(n + 1);
    solve();
    for (int i = 0; i <= n; i++)
        nxt[i] = -1;
    answer(nxt, X, Y);
}

#ifdef death
int main()
{
    fastIO;
    int nn,mm;
    vector<int> aa;
    cin >> mm >> nn;
    for (int i = 1; i <= nn; i++)
    {
        int x = 1;
        //cin >> x;
        aa.push_back(x);
    }

    create_circuit(nn, aa);

    return 0;
}
#endif

/*

1 12
1 2 1 2 1 2 1 2 1 2 1 2

*/

Compilation message

doll.cpp: In function 'void solve()':
doll.cpp:111:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  111 |         if ((1 << i) >= p.size())
      |             ~~~~~~~~~^~~~~~~~~~~
doll.cpp:118:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  118 |             for (int j = 0; j < id.size(); j++)
      |                             ~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 64 ms 5420 KB Output is correct
3 Correct 45 ms 4856 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 13 ms 1412 KB Output is correct
6 Correct 77 ms 6700 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 64 ms 5420 KB Output is correct
3 Correct 45 ms 4856 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 13 ms 1412 KB Output is correct
6 Correct 77 ms 6700 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 107 ms 8016 KB Output is correct
9 Correct 127 ms 8520 KB Output is correct
10 Correct 136 ms 11656 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 64 ms 5420 KB Output is correct
3 Correct 45 ms 4856 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 13 ms 1412 KB Output is correct
6 Correct 77 ms 6700 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 107 ms 8016 KB Output is correct
9 Correct 127 ms 8520 KB Output is correct
10 Correct 136 ms 11656 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 129 ms 11144 KB Output is correct
15 Correct 109 ms 7540 KB Output is correct
16 Correct 133 ms 10896 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 2 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 157 ms 11436 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 3 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 2 ms 204 KB Output is correct
7 Correct 2 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 77 ms 6640 KB Output is correct
3 Correct 86 ms 6584 KB Output is correct
4 Correct 136 ms 9416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 77 ms 6640 KB Output is correct
3 Correct 86 ms 6584 KB Output is correct
4 Correct 136 ms 9416 KB Output is correct
5 Correct 145 ms 10772 KB Output is correct
6 Correct 129 ms 10496 KB Output is correct
7 Correct 179 ms 10596 KB Output is correct
8 Correct 135 ms 10168 KB Output is correct
9 Correct 127 ms 6652 KB Output is correct
10 Correct 140 ms 10088 KB Output is correct
11 Correct 143 ms 9768 KB Output is correct
12 Correct 95 ms 6924 KB Output is correct
13 Correct 109 ms 7196 KB Output is correct
14 Correct 122 ms 7328 KB Output is correct
15 Correct 125 ms 7460 KB Output is correct
16 Correct 3 ms 472 KB Output is correct
17 Correct 107 ms 6520 KB Output is correct
18 Correct 84 ms 6852 KB Output is correct
19 Correct 86 ms 6772 KB Output is correct
20 Correct 123 ms 10036 KB Output is correct
21 Correct 131 ms 9732 KB Output is correct
22 Correct 122 ms 9876 KB Output is correct