QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#367393 | #91. Secret Permutation | Max_s_xaM | 0 | 0ms | 5712kb | C++20 | 3.7kb | 2024-03-25 22:13:22 | 2024-03-25 22:13:22 |
answer
#include <iostream>
#include <random>
#include <algorithm>
#include <vector>
#include <cmath>
typedef long long ll;
typedef double lf;
// #define DEBUG 1
struct IO
{
#define MAXSIZE (1 << 20)
#define isdigit(x) (x >= '0' && x <= '9')
char buf[MAXSIZE], *p1, *p2;
char pbuf[MAXSIZE], *pp;
#if DEBUG
#else
IO() : p1(buf), p2(buf), pp(pbuf) {}
~IO() {fwrite(pbuf, 1, pp - pbuf, stdout);}
#endif
#define gc() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, MAXSIZE, stdin), p1 == p2) ? ' ' : *p1++)
#define blank(x) (x == ' ' || x == '\n' || x == '\r' || x == '\t')
template <typename T>
void Read(T &x)
{
#if DEBUG
std::cin >> x;
#else
bool sign = 0; char ch = gc(); x = 0;
for (; !isdigit(ch); ch = gc())
if (ch == '-') sign = 1;
for (; isdigit(ch); ch = gc()) x = x * 10 + (ch ^ 48);
if (sign) x = -x;
#endif
}
void Read(char *s)
{
#if DEBUG
std::cin >> s;
#else
char ch = gc();
for (; blank(ch); ch = gc());
for (; !blank(ch); ch = gc()) *s++ = ch;
*s = 0;
#endif
}
void Read(char &c) {for (c = gc(); blank(c); c = gc());}
void Push(const char &c)
{
#if DEBUG
putchar(c);
#else
if (pp - pbuf == MAXSIZE) fwrite(pbuf, 1, MAXSIZE, stdout), pp = pbuf;
*pp++ = c;
#endif
}
template <typename T>
void Write(T x)
{
if (x < 0) x = -x, Push('-');
static T sta[35];
int top = 0;
do sta[top++] = x % 10, x /= 10; while (x);
while (top) Push(sta[--top] ^ 48);
}
template <typename T>
void Write(T x, char lst) {Write(x), Push(lst);}
} IO;
#define Read(x) IO.Read(x)
#define Write(x, y) IO.Write(x, y)
#define Put(x) IO.Push(x)
using namespace std;
const int MAXN = 260, B = 258;
#ifndef DEBUG
#include "permutation.h"
#endif
#ifdef DEBUG
namespace LOCAL
{
int n, a[MAXN], q;
inline void Solve()
{
Read(n), q = 0;
for (int i = 1; i <= n; i++) Read(a[i]);
}
}
int query(vector <int> p)
{
if (p.size() != LOCAL::n) {cout << "Query too short.\n"; exit(0);}
LOCAL::q++;
int sum = 0;
for (int i = 0; i < LOCAL::n - 1; i++) sum += abs(LOCAL::a[p[i]] - LOCAL::a[p[i + 1]]);
cout << "Query:\n";
for (int i = 0; i < LOCAL::n; i++) cout << p[i] << ' '; cout << '\n';
cout << sum << "\n";
return sum;
}
void answer(vector <int> p)
{
if (p.size() != LOCAL::n) {cout << "Answer too short.\n"; exit(0);}
cout << "Queries used: " << LOCAL::q << "\n";
for (int i = 0; i < LOCAL::n; i++) cout << p[i] << ' '; cout << '\n';
exit(0);
}
void solve(int N);
int main()
{
freopen("B.in", "r", stdin);
freopen("B.out", "w", stdout);
LOCAL::Solve();
solve(LOCAL::n);
return 0;
}
#endif
mt19937 Rand(102934);
int n, idx[MAXN], a[MAXN], d[MAXN];
vector <int> qry;
int ans[MAXN], rt;
bool vis[MAXN << 1];
inline bool Solve(int cur, int p, int l, int r)
{
if (r - l > n - 1 || vis[p + B]) return 0;
if (cur == n)
{
ans[cur] = p;
if (p + d[n] == 0 || p - d[n] == 0) return rt = l, 1;
return 0;
}
vis[p + B] = 1, ans[cur] = p;
if (Solve(cur + 1, p + d[cur], l, max(r, p + d[cur]))) return 1;
if (Solve(cur + 1, p - d[cur], min(l, p - d[cur]), r)) return 1;
vis[p + B] = 0;
return 0;
}
void solve(int N)
{
n = N;
qry.clear();
for (int i = 1; i <= n; i++) qry.push_back(i);
answer(qry);
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 5712kb
input:
7 5 7 1 3 2 4 6
output:
-1
result:
wrong answer Your answer is not correct.
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #1:
0%