Submission #255256

# Submission time Handle Problem Language Result Execution time Memory
255256 2020-07-31T16:26:10 Z davitmarg Mechanical Doll (IOI18_doll) C++17
2 / 100
70 ms 11696 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)
{
    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 bitcount(int x)
{
    int res = 0;
    while (x)
    {
        res += x % 2;
        x /= 2;
    }
    return res;
}

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

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

int han = 0;

int build(int st,int d,int val, int cnt, int x)
{
    int v = k;
    if (cnt > 1)
    {
        X[v - 1] = -add();
        build(st, d + 1, val, cnt / 2, x);
        Y[v - 1] = -add();
        return build(st, d + 1, val, cnt / 2, x + (1 << d));
    }
    else
    {
        int x1 = x-han;
        int x2 = x + (1 << d) - pos[val].size();
        if (x1 >= 0)
            X[v - 1] = pos[val][pos[val].size() - 1 - x1];
        else
            X[v - 1] = -st;

        if (x2 >= 0)
            Y[v - 1] = pos[val][pos[val].size() - 1 - x2];
        else
            Y[v - 1] = -st;
    }
    return 0;
}

void solve(int val)
{
    if (pos[val].empty())
        return;
    if (pos[val].size() == 1)
    {
        nxt[val] = pos[val][0];
        return;
    }
   
    for(int i=0;i<30;i++)
        if ((1 << i) >= pos[val].size())
        {
            nxt[val] = -add();
            han = (1 << i) - pos[val].size();
            build(k, 0, val, (1 << i) / 2, 0);
            break;
        }
}

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

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

    create_circuit(nn, aa);

    return 0;
}
#endif

/*

1 5
1 1 1 1 1

*/

Compilation message

doll.cpp: In function 'void solve(int)':
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) >= pos[val].size())
      |             ~~~~~~~~~^~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 4940 KB Output is correct
2 Correct 54 ms 8964 KB Output is correct
3 Correct 30 ms 8704 KB Output is correct
4 Correct 6 ms 4940 KB Output is correct
5 Correct 18 ms 6092 KB Output is correct
6 Correct 58 ms 10612 KB Output is correct
7 Correct 4 ms 4896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 4940 KB Output is correct
2 Correct 54 ms 8964 KB Output is correct
3 Correct 30 ms 8704 KB Output is correct
4 Correct 6 ms 4940 KB Output is correct
5 Correct 18 ms 6092 KB Output is correct
6 Correct 58 ms 10612 KB Output is correct
7 Correct 4 ms 4896 KB Output is correct
8 Incorrect 70 ms 11696 KB wrong motion
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 4940 KB Output is correct
2 Correct 54 ms 8964 KB Output is correct
3 Correct 30 ms 8704 KB Output is correct
4 Correct 6 ms 4940 KB Output is correct
5 Correct 18 ms 6092 KB Output is correct
6 Correct 58 ms 10612 KB Output is correct
7 Correct 4 ms 4896 KB Output is correct
8 Incorrect 70 ms 11696 KB wrong motion
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 4940 KB wrong motion
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 4940 KB wrong motion
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 4940 KB wrong motion
2 Halted 0 ms 0 KB -