제출 #941878

#제출 시각아이디문제언어결과실행 시간메모리
941878abcvuitunggioSecret Permutation (RMI19_permutation)C++17
10 / 100
3015 ms344 KiB
//#define NAM #ifndef NAM #include "permutation.h" #endif // NAM #include <bits/stdc++.h> using namespace std; #ifdef NAM int n,cnt_q=0; vector <int> p,q; int query(vector <int> v){ auto v2=v; sort(v2.begin(),v2.end()); int ch=1; for (int i=0;i<v2.size();i++) ch&=(v2[i]==i+1); if (v2.size()!=n||!ch){ cout << "Error: Not a permutation"; exit(0); } cnt_q++; int res=0; for (int i=0;i<n-1;i++) res+=abs(p[v[i]-1]-p[v[i+1]-1]); return res; } void answer(vector <int> v){ if (v!=p&&v!=q) cout << "Wrong Answer"; else{ cout << "Correct\n"; cout << "You asked " << cnt_q << " queries"; } } #endif // NAM void solve(int n){ vector <int> cur; for (int i=1;i<=n;i++) cur.push_back(i); int x=query(cur); while (x>n-1){ for (int i=0;i<n;i++) for (int j=i+1;j<n;j++){ reverse(cur.begin()+i,cur.begin()+j+1); int y=query(cur); if (y<x) x=y; else reverse(cur.begin()+i,cur.begin()+j+1); } } vector <int> ans(n,0); for (int i=1;i<=n;i++) ans[cur[i-1]-1]=i; answer(ans); } #ifdef NAM int main(){ cin >> n; for (int i=1;i<=n;i++) p.push_back(i); random_shuffle(p.begin(),p.end()); for (int i:p) q.push_back(n-i+1); solve(n); } #endif // NAM

컴파일 시 표준 에러 (stderr) 메시지

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);
      |   ~~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...