QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#883314 | #4356. Giraffes | Mousa_Aboubaker# | 10 | 2747ms | 3712kb | C++20 | 2.7kb | 2025-02-05 15:47:02 | 2025-02-05 15:47:08 |
Judging History
answer
#pragma GCC optimize("O3", "Ofast", "unroll-loops")
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <deque>
#include <climits>
#include <cmath>
#include <numeric>
#include <string>
#include <bitset>
#include <assert.h>
#include <iomanip>
#include <bit>
using namespace std;
template <typename T>
using pqg = priority_queue<T, vector<T>, greater<T>>;
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/
/*
#include <bits/stdc++.h>
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define getrand(l, r) uniform_int_distribution<int>(l, r)(rng)
*/
const long long infl = 1e18 + 1;
const int inf = 1e9 + 1;
const int mod1 = 1e9 + 7;
const int mod2 = 998244353;
const long double eps = 1e-7;
const int mod = mod1;
int add(int a, int b) { return (a + b) % mod; }
int sub(int a, int b) { return (a - b + mod) % mod; }
int mul(int a, int b) { return (int)((long long)a * b % mod); }
int pwr(int a, int b = mod - 2)
{
int res = 1;
for (; b > 0; b >>= 1, a = mul(a, a))
if (b & 1)
res = mul(res, a);
return res;
}
template <typename T>
bool chmax(T &a, T b)
{
if (b > a)
{
a = b;
return true;
}
return false;
}
template <typename T>
bool chmin(T &a, T b)
{
if (b < a)
{
a = b;
return true;
}
return false;
}
#define all(x) x.begin(), x.end()
#define SZ(x) (int)x.size()
#define vec vector
using ll = long long;
void solve()
{
int n;
cin >> n;
vec<int> a(n);
for(auto &i: a)
cin >> i;
int mn = inf;
vec<int> b = a;
sort(all(a));
do
{
bool can = true;
for(int l = 0; l < n; l++)
{
vec<int> c;
for(int r = l; r < n; r++)
{
c.push_back(a[r]);
bool greater = false, less = false;
for(int k = 1; k < SZ(c) - 1; k++)
{
greater |= c[k] > c[0] and c[k] > c[SZ(c) - 1];
less |= c[k] < c[0] and c[k] < c[SZ(c) - 1];
}
can &= not (greater and less);
}
}
if(not can)
{
continue;
}
int diff = 0;
for(int i = 0; i < n; i++)
diff += a[i] != b[i];
chmin(mn, diff);
} while (next_permutation(all(a)));
cout << mn;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
// cin >> t;
while (t--)
{
solve();
cout << (t ? "\n" : "");
}
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 10
Accepted
Test #1:
score: 10
Accepted
time: 1ms
memory: 3584kb
input:
1 1
output:
0
result:
ok single line: '0'
Test #2:
score: 10
Accepted
time: 0ms
memory: 3584kb
input:
2 2 1
output:
0
result:
ok single line: '0'
Test #3:
score: 10
Accepted
time: 0ms
memory: 3584kb
input:
3 1 2 3
output:
0
result:
ok single line: '0'
Test #4:
score: 10
Accepted
time: 0ms
memory: 3584kb
input:
4 3 1 4 2
output:
2
result:
ok single line: '2'
Test #5:
score: 10
Accepted
time: 0ms
memory: 3712kb
input:
5 3 4 5 1 2
output:
2
result:
ok single line: '2'
Test #6:
score: 10
Accepted
time: 0ms
memory: 3584kb
input:
6 1 5 6 2 4 3
output:
2
result:
ok single line: '2'
Test #7:
score: 10
Accepted
time: 0ms
memory: 3584kb
input:
6 1 6 3 4 2 5
output:
0
result:
ok single line: '0'
Test #8:
score: 10
Accepted
time: 2ms
memory: 3584kb
input:
7 5 3 4 6 2 7 1
output:
0
result:
ok single line: '0'
Test #9:
score: 10
Accepted
time: 2ms
memory: 3584kb
input:
7 5 3 7 1 2 6 4
output:
3
result:
ok single line: '3'
Test #10:
score: 10
Accepted
time: 3ms
memory: 3584kb
input:
7 5 2 3 6 7 1 4
output:
2
result:
ok single line: '2'
Subtask #2:
score: 0
Time Limit Exceeded
Test #11:
score: 22
Accepted
time: 19ms
memory: 3584kb
input:
8 7 2 1 8 3 5 4 6
output:
3
result:
ok single line: '3'
Test #12:
score: 22
Accepted
time: 228ms
memory: 3584kb
input:
9 3 1 5 6 8 4 7 9 2
output:
3
result:
ok single line: '3'
Test #13:
score: 22
Accepted
time: 2747ms
memory: 3584kb
input:
10 4 6 5 7 1 2 3 8 9 10
output:
2
result:
ok single line: '2'
Test #14:
score: 0
Time Limit Exceeded
input:
11 2 10 3 11 1 5 8 6 4 7 9
output:
result:
Subtask #3:
score: 0
Time Limit Exceeded
Test #21:
score: 0
Time Limit Exceeded
input:
29 7 22 11 16 27 1 24 12 6 21 13 2 10 8 25 15 4 19 17 9 23 5 14 20 18 28 26 29 3
output:
result:
Subtask #4:
score: 0
Time Limit Exceeded
Test #31:
score: 0
Time Limit Exceeded
input:
2317 1841 533 998 38 1358 1204 1174 176 581 1719 550 906 35 101 442 1068 1781 601 1368 2190 2095 919 2186 1134 1814 625 90 2007 653 186 204 997 1607 1675 45 806 483 299 27 935 1070 1425 1822 1712 2074 2259 264 840 1960 1045 1742 1185 577 142 980 151 2136 2143 955 462 1373 395 1300 185 637 734 803 13...