Submission #134252

# Submission time Handle Problem Language Result Execution time Memory
134252 2019-07-22T09:40:39 Z Kastanda Swap (BOI16_swap) C++11
100 / 100
90 ms 6776 KB
// ItnoE
#include<bits/stdc++.h>
using namespace std;
const int N = 400005;
int n, A[N], R[N], M[N];
inline int GetBest(int id)
{
    int Mn = INT_MAX;
    while (id)
    {
        if (M[id] != 1)
            Mn = min(Mn, A[id]);
        if (!M[id])
            break;
        if ((id & 1) && M[id ^ 1])
        {
            Mn = min(Mn, A[id ^ 1]);
            if (M[id ^ 1] == 1)
                break;
        }
        id >>= 1;
    }
    return (Mn);
}
inline void Del(int id, int val)
{
    while (id)
    {
        if (A[id] == val)
            {M[id] = 0; break;}
        if (id & 1)
        {
            if (A[id ^ 1] == val)
                {M[id ^ 1] = M[id] = 1; break;}
            else
                M[id ^ 1] = 0;
        }
        M[id] = 1;
        id >>= 1;
    }
}
int main()
{
    scanf("%d", &n);
    memset(A, 63, sizeof(A));
    for (int i = 1; i <= n; i ++)
        scanf("%d", &A[i]), M[i] = 2;
    M[1] = 0;
    for (int i = 1; i <= n; i ++)
    {
        int lc = i << 1, rc = lc ^ 1;
        int Mn = min({GetBest(i), A[lc], A[rc]});
        R[i] = Mn;
        if (Mn == GetBest(i))
            M[lc] = M[rc] = 0, Del(i, Mn);
        if (Mn == A[lc])
            M[lc] = 1, M[rc] = 0;
        if (Mn == A[rc])
            M[rc] = 1;
    }
    for (int i = 1; i <= n; i ++)
        printf("%d ", R[i]);
}

Compilation message

swap.cpp: In function 'int main()':
swap.cpp:44:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
swap.cpp:47:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &A[i]), M[i] = 2;
         ~~~~~~~~~~~~~~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2040 KB Output is correct
2 Correct 3 ms 1912 KB Output is correct
3 Correct 3 ms 1912 KB Output is correct
4 Correct 3 ms 2040 KB Output is correct
5 Correct 3 ms 1912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2040 KB Output is correct
2 Correct 3 ms 1912 KB Output is correct
3 Correct 3 ms 1912 KB Output is correct
4 Correct 3 ms 2040 KB Output is correct
5 Correct 3 ms 1912 KB Output is correct
6 Correct 3 ms 1912 KB Output is correct
7 Correct 3 ms 1912 KB Output is correct
8 Correct 3 ms 1912 KB Output is correct
9 Correct 3 ms 1912 KB Output is correct
10 Correct 3 ms 1912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2040 KB Output is correct
2 Correct 3 ms 1912 KB Output is correct
3 Correct 3 ms 1912 KB Output is correct
4 Correct 3 ms 2040 KB Output is correct
5 Correct 3 ms 1912 KB Output is correct
6 Correct 3 ms 1912 KB Output is correct
7 Correct 3 ms 1912 KB Output is correct
8 Correct 3 ms 1912 KB Output is correct
9 Correct 3 ms 1912 KB Output is correct
10 Correct 3 ms 1912 KB Output is correct
11 Correct 4 ms 1912 KB Output is correct
12 Correct 3 ms 1912 KB Output is correct
13 Correct 3 ms 1912 KB Output is correct
14 Correct 4 ms 1940 KB Output is correct
15 Correct 4 ms 1912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2040 KB Output is correct
2 Correct 3 ms 1912 KB Output is correct
3 Correct 3 ms 1912 KB Output is correct
4 Correct 3 ms 2040 KB Output is correct
5 Correct 3 ms 1912 KB Output is correct
6 Correct 3 ms 1912 KB Output is correct
7 Correct 3 ms 1912 KB Output is correct
8 Correct 3 ms 1912 KB Output is correct
9 Correct 3 ms 1912 KB Output is correct
10 Correct 3 ms 1912 KB Output is correct
11 Correct 4 ms 1912 KB Output is correct
12 Correct 3 ms 1912 KB Output is correct
13 Correct 3 ms 1912 KB Output is correct
14 Correct 4 ms 1940 KB Output is correct
15 Correct 4 ms 1912 KB Output is correct
16 Correct 18 ms 3064 KB Output is correct
17 Correct 20 ms 3064 KB Output is correct
18 Correct 18 ms 3064 KB Output is correct
19 Correct 23 ms 3056 KB Output is correct
20 Correct 23 ms 3064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2040 KB Output is correct
2 Correct 3 ms 1912 KB Output is correct
3 Correct 3 ms 1912 KB Output is correct
4 Correct 3 ms 2040 KB Output is correct
5 Correct 3 ms 1912 KB Output is correct
6 Correct 3 ms 1912 KB Output is correct
7 Correct 3 ms 1912 KB Output is correct
8 Correct 3 ms 1912 KB Output is correct
9 Correct 3 ms 1912 KB Output is correct
10 Correct 3 ms 1912 KB Output is correct
11 Correct 4 ms 1912 KB Output is correct
12 Correct 3 ms 1912 KB Output is correct
13 Correct 3 ms 1912 KB Output is correct
14 Correct 4 ms 1940 KB Output is correct
15 Correct 4 ms 1912 KB Output is correct
16 Correct 18 ms 3064 KB Output is correct
17 Correct 20 ms 3064 KB Output is correct
18 Correct 18 ms 3064 KB Output is correct
19 Correct 23 ms 3056 KB Output is correct
20 Correct 23 ms 3064 KB Output is correct
21 Correct 67 ms 6748 KB Output is correct
22 Correct 62 ms 6776 KB Output is correct
23 Correct 63 ms 6772 KB Output is correct
24 Correct 90 ms 6748 KB Output is correct
25 Correct 87 ms 6776 KB Output is correct