답안 #685397

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
685397 2023-01-24T09:50:22 Z annie2018 Secret Permutation (RMI19_permutation) C++17
50 / 100
5000 ms 336 KB
#include "permutation.h"
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define all(a) (a).begin(), (a).end()
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define sz() size()
#define fr first
#define sc second
#define pi pair<int,int>
#define pii pair<pair<int,int>,int>
#define mp make_pair
//#define int long long
#define rc(s) return cout<<s,0
#define rcc(s) cout<<s,exit(0)
using namespace std;

const int mod=1e9+7;
const int modp=1999999973;
const int modulo=998244353;

int n;
bitset<257>viz;
vector<int>v,arr(257),ans(257),fin(257);
vector<int>answ;

void DFS(int curr){
    viz[ans[curr]]=1;
    if(curr==n && abs(ans[curr]-ans[1])==arr[n]){
        for(int i=1;i<=n;i++){
            fin[v[i-1]]=ans[i];
        }
        for(int i=1;i<=n;i++){
            answ.push_back(fin[i]);
        }
        answer(answ);
        exit(0);
    }
    else{
        int x1=(ans[curr] - arr[curr]);
        int x2=(ans[curr] + arr[curr]);
        if(x1>=1 && x1<=n && viz[x1]==0 && abs(x1-ans[curr])==arr[curr]){
            ans[curr+1]=(x1);
            DFS(curr+1);
        }
        if(x2>=1 && x2<=n && viz[x2]==0 && abs(x2-ans[curr])==arr[curr]){
            ans[curr+1]=(x2);
            DFS(curr+1);
        }
    }
    viz[ans[curr]]=0;
    ans[curr]=0;
}

void solve(int N){
    ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
    srand(chrono::steady_clock::now().time_since_epoch().count());
    n=N;
    for(int i=1;i<=n;i++){
        v.push_back(i);
    }
    //random_shuffle(all(v));
    for(int i=1;i<=n;i++){
        rotate(v.begin(),v.begin()+1,v.end());
        arr[i] = query(v);
    }
    rotate(v.begin(),v.begin()+1,v.end());
    int sum=0;
    for(int i=1;i<=n;i++){
        sum+=arr[i];
    }
    sum/=(n-1);
    for(int i=1;i<=n;i++) arr[i]=(sum-arr[i]);
    arr[n+1]=arr[1];
    for(int i=1;i<=n;i++) arr[i]=arr[i+1];
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++) ans[j]=0;
        ans[1]=i;
        viz.reset();
        DFS(1);
    }
}

Compilation message

stub.cpp: In function 'int query(int*)':
stub.cpp:15:9: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |   fscanf(stdin, "%d", &x);
      |   ~~~~~~^~~~~~~~~~~~~~~~~
stub.cpp: In function 'int main(int, char**)':
stub.cpp:48:9: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |   fscanf(stdin, "%d", &N);
      |   ~~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 0 ms 208 KB Output is correct
6 Correct 0 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 0 ms 208 KB Output is correct
6 Correct 0 ms 208 KB Output is correct
7 Correct 1 ms 208 KB Output is correct
8 Correct 1 ms 208 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 1 ms 208 KB Output is correct
12 Correct 1 ms 208 KB Output is correct
13 Correct 1 ms 208 KB Output is correct
14 Correct 1 ms 208 KB Output is correct
15 Correct 1 ms 208 KB Output is correct
16 Correct 1 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 0 ms 208 KB Output is correct
6 Correct 0 ms 208 KB Output is correct
7 Correct 1 ms 208 KB Output is correct
8 Correct 1 ms 208 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 1 ms 208 KB Output is correct
12 Correct 1 ms 208 KB Output is correct
13 Correct 1 ms 208 KB Output is correct
14 Correct 1 ms 208 KB Output is correct
15 Correct 1 ms 208 KB Output is correct
16 Correct 1 ms 208 KB Output is correct
17 Correct 11 ms 324 KB Output is correct
18 Correct 10 ms 328 KB Output is correct
19 Correct 11 ms 308 KB Output is correct
20 Correct 13 ms 312 KB Output is correct
21 Correct 84 ms 336 KB Output is correct
22 Correct 164 ms 316 KB Output is correct
23 Correct 14 ms 328 KB Output is correct
24 Execution timed out 5008 ms 288 KB Time limit exceeded
25 Halted 0 ms 0 KB -