Submission #1040320

# Submission time Handle Problem Language Result Execution time Memory
1040320 2024-08-01T01:02:33 Z vjudge1 Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
0 / 100
3000 ms 46612 KB
#include <bits/stdc++.h>
using namespace std;

int a[1000005];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
        cin >> a[i];

    while (m--)
    {
        int l, r, w;
        cin >> l >> r >> w;

        vector<int> b(r - l + 1);
        for (int j = 0; j < r - l + 1; j++)
        {
            b[j] = a[l + j];
        }

        vector<int> c = b;
        sort(c.begin(), c.end());

        bool res = true;
        unordered_map<int, int> pos_map;
        for (int j = 0; j < b.size(); j++) {
            pos_map[b[j]] = j;
        }

        for (int j = 0; j < c.size(); j++)
        {
            if (b[j] != c[j])
            {
                int pos = pos_map[c[j]];
                for (int k = pos; k > j; k--)
                {
                    if (b[k] + b[k - 1] <= w)
                    {
                        swap(b[k], b[k - 1]);
                        pos_map[b[k]] = k;
                        pos_map[b[k - 1]] = k - 1;
                    }
                    else
                    {
                        res = false;
                        break;
                    }
                }
                if (!res)
                    break;
            }
        }
        if (res) cout << 1 << '\n';
        else cout << 0 << '\n';
    }
    return 0;
}

Compilation message

sortbooks.cpp: In function 'int main()':
sortbooks.cpp:32:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |         for (int j = 0; j < b.size(); j++) {
      |                         ~~^~~~~~~~~~
sortbooks.cpp:36:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |         for (int j = 0; j < c.size(); j++)
      |                         ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 472 KB Output is correct
3 Correct 3 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 500 KB Output is correct
6 Correct 29 ms 564 KB Output is correct
7 Correct 31 ms 344 KB Output is correct
8 Correct 23 ms 552 KB Output is correct
9 Correct 28 ms 348 KB Output is correct
10 Incorrect 3 ms 348 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 472 KB Output is correct
3 Correct 3 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 500 KB Output is correct
6 Correct 29 ms 564 KB Output is correct
7 Correct 31 ms 344 KB Output is correct
8 Correct 23 ms 552 KB Output is correct
9 Correct 28 ms 348 KB Output is correct
10 Incorrect 3 ms 348 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3024 ms 46612 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3051 ms 2296 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 472 KB Output is correct
3 Correct 3 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 500 KB Output is correct
6 Correct 29 ms 564 KB Output is correct
7 Correct 31 ms 344 KB Output is correct
8 Correct 23 ms 552 KB Output is correct
9 Correct 28 ms 348 KB Output is correct
10 Incorrect 3 ms 348 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 472 KB Output is correct
3 Correct 3 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 500 KB Output is correct
6 Correct 29 ms 564 KB Output is correct
7 Correct 31 ms 344 KB Output is correct
8 Correct 23 ms 552 KB Output is correct
9 Correct 28 ms 348 KB Output is correct
10 Incorrect 3 ms 348 KB Output isn't correct
11 Halted 0 ms 0 KB -