Submission #1122826

#TimeUsernameProblemLanguageResultExecution timeMemory
1122826cpdreamerGiraffes (JOI22_giraffes)C++20
10 / 100
4 ms328 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define P pair #define S second #define F first #define all(v) v.begin(),v.end() #define V vector #define pb push_back const ll MOD=998244353; void file() { freopen("input.txt.txt", "r", stdin); freopen("output.txt.txt", "w", stdout); } void setIO(string s = "") { if (!s.empty()){ freopen((s + ".in").c_str(), "r", stdin); freopen((s + ".out").c_str(), "w", stdout); } ios::sync_with_stdio(false); cin.tie(0); } bool check(int n,V<int>A){ for(int i=0;i<n-1;i++){ for(int j=i+1;j<n;j++){ int mind=INT_MAX; int maxd=INT_MIN; for(int g=i;g<=j;g++){ mind=min(mind,A[g]); maxd=max(maxd,A[g]); } if(mind<min(A[i],A[j]) && maxd>max(A[i],A[j])) return false; } } return true; } void solve() { int n; cin>>n; V<int>A(n); for(int i=0;i<n;i++){ cin>>A[i]; } if(check(n,A)){ cout<<0<<endl; return; } int ans=INT_MAX; for(int mask=0;mask<(1<<(n+1));mask++){ V<int>B=A; V<int>C; V<int>pos; for(int j=0;j<n;j++){ if(((1<<j)&mask)!=0){ pos.pb(j); C.pb(A[j]); } } sort(all(C)); for(int i=0;i<(int)pos.size();i++){ B[pos[i]]=C[i]; } if(check(n,B)){ ans=min(ans,(int)pos.size()); } reverse(all(C)); for(int i=0;i<(int)pos.size();i++){ B[pos[i]]=C[i]; } if(check(n,B)){ ans=min(ans,(int)pos.size()); } } cout<<ans<<endl; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); //file(); solve(); }

Compilation message (stderr)

giraffes.cpp: In function 'void file()':
giraffes.cpp:12:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |     freopen("input.txt.txt", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
giraffes.cpp:13:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |     freopen("output.txt.txt", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
giraffes.cpp: In function 'void setIO(std::string)':
giraffes.cpp:17:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |         freopen((s + ".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
giraffes.cpp:18:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |         freopen((s + ".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...