제출 #1146406

#제출 시각아이디문제언어결과실행 시간메모리
1146406ReLicePermutation Recovery (info1cup17_permutation)C++20
0 / 100
2 ms5388 KiB
#include <bits/stdc++.h> #define ll long long #define ld double #define pb push_back #define pf push_front #define ins insert #define fr first #define sc second #define endl "\n" #define all(x) x.begin(), x.end() using namespace std; void fre(string& name){freopen((name + ".in").c_str(), "r", stdin);freopen((name + ".out").c_str(), "w", stdout);} void start(){ios_base::sync_with_stdio(NULL);cin.tie(nullptr);cout.tie(nullptr);} const ll N = 2e5 + 5; const ll inf = 1e9; const ll mod = 1e9 + 7; vector<vector<ll>> g(N); ll ans[N]; ll vis[N]; vector<ll> tour; void dfs(ll v){ for(auto i : g[v]){ if(vis[i]) continue; dfs(i); } vis[v] = 1; tour.pb(v); } void solve() { ll i, j; ll n; cin>>n; ll q[n + 1]; ll a[n + 1]; q[0] = 0; vector<ll> mn, mx; for(i=1;i<=n;i++) { cin>>q[i]; a[i] = q[i] - q[i - 1]; if(i > 1){ if(a[i] > a[i - 1]) g[i - 1].pb(i); else g[i].pb(i - 1); } if(a[i] == 1){ mn.pb(i); for(j=i - 1;j>0;j--){ if(j < i - 1) g[i].pb(j); //cout<<i<<' '<<j<<endl; if(a[j] == 1) break; } } else if(a[i] == q[i - 1] + 1){ mx.pb(a[i]); for(j=i - 1;j>0;j--){ if(j < i - 1) g[j].pb(i); //cout<<j<<' '<<i<<endl; if(a[j] == q[j - 1] + 1) break; } } } for(i=mn.back() + 2;i<=n;i++){ g[mn.back()].pb(i); } for(i=mx.back() + 2;i<=n;i++){ g[i].pb(mx.back()); } dfs(mn.back()); reverse(all(tour)); for(i=0;i<n;i++){ ans[tour[i]] = i + 1; } for(i=1;i<=n;i++) cout<<ans[i]<<' '; cout<<endl; } signed main(){ start(); ll t = 1; //cin>>t; while(t--) solve(); } /* */

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

Main.cpp: In function 'void fre(std::string&)':
Main.cpp:13:31: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 | void fre(string& name){freopen((name + ".in").c_str(), "r", stdin);freopen((name + ".out").c_str(), "w", stdout);}
      |                        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:13:75: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 | void fre(string& name){freopen((name + ".in").c_str(), "r", stdin);freopen((name + ".out").c_str(), "w", stdout);}
      |                                                                    ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...