Submission #550141

# Submission time Handle Problem Language Result Execution time Memory
550141 2022-04-17T10:54:26 Z fcmalkcin The Collection Game (BOI21_swaps) C++17
100 / 100
10 ms 484 KB
#include "swaps.h"


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

#define ll int
#define pll pair<ll,ll>
#define ff first
#define ss second
#define endl "\n"
#define pb push_back
#define F(i,a,b) for(ll i=a;i<=b;i++)

const ll maxn=3e5+10 ;
const ll base=1e9;
const ll mod= 1e9+7 ;

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

/// have medal in APIO
/// goal 2/8

ll len;
ll cnt=0;
vector<pll> vt;
map<pll,ll> mp;
ll a[maxn];
ll b[maxn];

void get()
{
    vector<ll> vt1=visit();
    for (int t=0; t<vt1.size(); t++)
    {
        mp[vt[t]]=vt1[t];
    }
    vt.clear();
}
void setup(ll x, ll y)
{
    if (x<=len&&y<=len)
    {
        schedule(x,y);
        vt.pb(make_pair(x,y));
    }
    else
    {
        if (x>len&&y>len)
        {
            mp[make_pair(x,y)]=(x>y);
        }
        else if (x>len)
        {
            mp[make_pair(x,y)]=0;
        }
        else
        {
            mp[make_pair(x,y)]=1;
        }
    }
}
void ans(vector<ll> vt)
{
    answer(vt);
}
void solve(ll n,ll v)
{
    ll p=1;
    while (p<n)
        p*=2;
    len=n;
    vector<ll> vt;
    for (int t=1; t<=p; t++)
        vt.pb(t);
    for (int t=2; t<=p; t*=2)
    {
        vector<vector<ll>> vt1;
        for (int i=1; i<=p; i+=t)
        {
            vector<ll> vt2;
            for (int k=i; k<=i+t/2-1; k++)
            {
                vt2.pb(vt[k-1]);
            }
            for (int k=i+t-1; k>=i+t/2; k--)
            {
                vt2.pb(vt[k-1]);
            }
            vt1.pb(vt2);
        }
        while (vt1[0].size()!=1)
        {
            mp.clear();
            ll len=vt1[0].size();
            for (auto p:vt1)
            {
                for (int i=0; i<len/2; i++)
                {
                    setup(p[i],p[i+len/2]);
                }
            }
            get();
            vector<vector<ll>> vt2;
            for (auto p1:vt1)
            {
                vector<ll> p=p1;
                assert(p.size()==len);
                for (int i=0; i<len/2; i++)
                {
                    if (mp[make_pair(p[i],p[i+len/2])]==0)
                        swap(p[i],p[i+len/2]);
                }
                vector<ll> vtnxt1;
                vector<ll> vtnxt2;
                for (int i=0; i<len/2; i++)
                {
                    vtnxt1.pb(p[i]);
                }
                for (int i=len/2; i<len; i++)
                {
                    vtnxt2.pb(p[i]);
                }
                vt2.pb(vtnxt1);
                vt2.pb(vtnxt2);
            }
            swap(vt1,vt2);
            /* cout <<t<<" "<<len<<" kt"<<endl;

             for (int i=1; i<=n; i++)
             {
                 cout <<a[i]<<" ";
             }
             cout <<endl;
             for (auto to:vt1)
             {
                 for (auto h:to) cout <<h<<" ";
                 cout <<endl;
             }
             cout <<endl;*/
        }
        vt.clear();
        for (auto p:vt1)
        {
            vt.pb(p[0]);
        }
    }
    vector<ll> res;
    for (int i=0; i<n; i++)
        res.pb(vt[i]);
    ans(res);
}

/*int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    if (fopen("test.inp","r"))
    {
        freopen("test.inp","r",stdin);
        freopen("test.out","w",stdout);
    }
}*/

Compilation message

swaps.cpp: In function 'void get()':
swaps.cpp:34:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |     for (int t=0; t<vt1.size(); t++)
      |                   ~^~~~~~~~~~~
In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from swaps.cpp:4:
swaps.cpp: In function 'void solve(int, int)':
swaps.cpp:108:32: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  108 |                 assert(p.size()==len);
      |                        ~~~~~~~~^~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Correct
2 Correct 2 ms 332 KB Correct
3 Correct 4 ms 336 KB Correct
4 Correct 8 ms 388 KB Correct
5 Correct 7 ms 392 KB Correct
6 Correct 9 ms 392 KB Correct
7 Correct 8 ms 392 KB Correct
8 Correct 8 ms 392 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Correct
2 Correct 3 ms 336 KB Correct
3 Correct 5 ms 356 KB Correct
4 Correct 8 ms 388 KB Correct
5 Correct 8 ms 388 KB Correct
6 Correct 9 ms 392 KB Correct
7 Correct 8 ms 388 KB Correct
8 Correct 9 ms 396 KB Correct
9 Correct 8 ms 388 KB Correct
10 Correct 8 ms 392 KB Correct
11 Correct 8 ms 396 KB Correct
12 Correct 8 ms 388 KB Correct
13 Correct 8 ms 388 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Correct
2 Correct 2 ms 336 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Correct
2 Correct 2 ms 336 KB Correct
3 Correct 1 ms 332 KB Correct
4 Correct 2 ms 208 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Correct
2 Correct 3 ms 208 KB Correct
3 Correct 4 ms 356 KB Correct
4 Correct 10 ms 392 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Correct
2 Correct 3 ms 208 KB Correct
3 Correct 4 ms 356 KB Correct
4 Correct 10 ms 392 KB Correct
5 Correct 1 ms 208 KB Correct
6 Correct 2 ms 208 KB Correct
7 Correct 5 ms 356 KB Correct
8 Correct 7 ms 388 KB Correct
9 Correct 8 ms 392 KB Correct
10 Correct 7 ms 388 KB Correct
11 Correct 8 ms 392 KB Correct
12 Correct 8 ms 396 KB Correct
13 Correct 1 ms 208 KB Correct
14 Correct 2 ms 336 KB Correct
15 Correct 4 ms 336 KB Correct
16 Correct 8 ms 384 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Correct
2 Correct 2 ms 208 KB Correct
3 Correct 4 ms 336 KB Correct
4 Correct 7 ms 392 KB Correct
5 Correct 8 ms 392 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Correct
2 Correct 2 ms 208 KB Correct
3 Correct 4 ms 336 KB Correct
4 Correct 7 ms 392 KB Correct
5 Correct 8 ms 392 KB Correct
6 Correct 1 ms 208 KB Correct
7 Correct 2 ms 208 KB Correct
8 Correct 4 ms 344 KB Correct
9 Correct 8 ms 388 KB Correct
10 Correct 8 ms 392 KB Correct
11 Correct 7 ms 392 KB Correct
12 Correct 7 ms 388 KB Correct
13 Correct 7 ms 396 KB Correct
14 Correct 10 ms 392 KB Correct
15 Correct 8 ms 396 KB Correct
16 Correct 7 ms 388 KB Correct
17 Correct 8 ms 336 KB Correct
18 Correct 8 ms 392 KB Correct
19 Correct 1 ms 208 KB Correct
20 Correct 2 ms 332 KB Correct
21 Correct 4 ms 336 KB Correct
22 Correct 8 ms 400 KB Correct
23 Correct 10 ms 368 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Correct
2 Correct 2 ms 336 KB Correct
3 Correct 3 ms 336 KB Correct
4 Correct 8 ms 396 KB Correct
5 Correct 8 ms 372 KB Correct
6 Correct 9 ms 368 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Correct
2 Correct 2 ms 336 KB Correct
3 Correct 3 ms 336 KB Correct
4 Correct 8 ms 396 KB Correct
5 Correct 8 ms 372 KB Correct
6 Correct 9 ms 368 KB Correct
7 Correct 1 ms 208 KB Correct
8 Correct 3 ms 208 KB Correct
9 Correct 4 ms 300 KB Correct
10 Correct 9 ms 388 KB Correct
11 Correct 9 ms 392 KB Correct
12 Correct 7 ms 392 KB Correct
13 Correct 9 ms 392 KB Correct
14 Correct 9 ms 388 KB Correct
15 Correct 8 ms 392 KB Correct
16 Correct 7 ms 396 KB Correct
17 Correct 8 ms 392 KB Correct
18 Correct 8 ms 396 KB Correct
19 Correct 8 ms 392 KB Correct
20 Correct 1 ms 208 KB Correct
21 Correct 2 ms 208 KB Correct
22 Correct 4 ms 344 KB Correct
23 Correct 9 ms 396 KB Correct
24 Correct 8 ms 372 KB Correct
25 Correct 8 ms 372 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Correct
2 Correct 2 ms 304 KB Correct
3 Correct 3 ms 336 KB Correct
4 Correct 8 ms 388 KB Correct
5 Correct 7 ms 364 KB Correct
6 Correct 8 ms 372 KB Correct
7 Correct 8 ms 372 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Correct
2 Correct 2 ms 304 KB Correct
3 Correct 3 ms 336 KB Correct
4 Correct 8 ms 388 KB Correct
5 Correct 7 ms 364 KB Correct
6 Correct 8 ms 372 KB Correct
7 Correct 8 ms 372 KB Correct
8 Correct 0 ms 208 KB Correct
9 Correct 1 ms 208 KB Correct
10 Correct 2 ms 208 KB Correct
11 Correct 3 ms 336 KB Correct
12 Correct 9 ms 388 KB Correct
13 Correct 8 ms 484 KB Correct
14 Correct 7 ms 384 KB Correct
15 Correct 7 ms 392 KB Correct
16 Correct 7 ms 392 KB Correct
17 Correct 8 ms 388 KB Correct
18 Correct 8 ms 392 KB Correct
19 Correct 8 ms 388 KB Correct
20 Correct 7 ms 392 KB Correct
21 Correct 7 ms 392 KB Correct
22 Correct 1 ms 208 KB Correct
23 Correct 2 ms 332 KB Correct
24 Correct 5 ms 360 KB Correct
25 Correct 8 ms 392 KB Correct
26 Correct 9 ms 388 KB Correct
27 Correct 8 ms 380 KB Correct
28 Correct 7 ms 376 KB Correct