Submission #1331364
Source Code Expand
#include<iostream> #include<cstdio> #include<algorithm> #include<cmath> #include<cstring> #include<vector> #include<queue> #include<set> #include<map> #include<stack> #include<bitset> #include<ext/pb_ds/priority_queue.hpp> using namespace std; const int maxn = 2E5 + 5; int n,A[maxn],T[maxn],f[maxn],pos[maxn]; inline bool Check(int x,int y,int z) { if (pos[x] < pos[y] && pos[y] < pos[z]) return 1; if (pos[z] < pos[x] && pos[x] < pos[y]) return 1; if (pos[y] < pos[z] && pos[z] < pos[x]) return 1; return 0; } int main() { #ifdef DMC freopen("DMC.txt","r",stdin); #endif cin >> n; for (int i = 1; i <= n; i++) scanf("%d",&A[i]),pos[A[i]] = i; for (int i = n - 1; i; i--) { if (!T[i + 1]) { if (pos[i + 1] < pos[i]) { T[i] = 1; f[i] = i + 1; } } else { if (Check(f[i + 1],i,i + 1)) { T[i] = T[i + 1]; f[i] = f[i + 1]; } else { T[i] = T[i + 1] + 1; f[i] = i + 1; } } } cout << T[1] << endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | F - Strange Sorting |
User | Charming_Chen |
Language | C++14 (GCC 5.4.1) |
Score | 2400 |
Code Size | 1031 Byte |
Status | AC |
Exec Time | 25 ms |
Memory | 3328 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:34:62: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] for (int i = 1; i <= n; i++) scanf("%d",&A[i]),pos[A[i]] = i; ^
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 2400 / 2400 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | sample1.txt, sample2.txt, sample3.txt |
All | sample1.txt, sample2.txt, sample3.txt, in1.txt, in10.txt, in11.txt, in12.txt, in13.txt, in14.txt, in15.txt, in16.txt, in17.txt, in18.txt, in19.txt, in2.txt, in20.txt, in21.txt, in22.txt, in23.txt, in3.txt, in4.txt, in5.txt, in6.txt, in7.txt, in8.txt, in9.txt, sample1.txt, sample2.txt, sample3.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
in1.txt | AC | 24 ms | 3328 KB |
in10.txt | AC | 25 ms | 3328 KB |
in11.txt | AC | 24 ms | 3328 KB |
in12.txt | AC | 25 ms | 3328 KB |
in13.txt | AC | 25 ms | 3328 KB |
in14.txt | AC | 24 ms | 3328 KB |
in15.txt | AC | 24 ms | 3328 KB |
in16.txt | AC | 25 ms | 3328 KB |
in17.txt | AC | 24 ms | 3328 KB |
in18.txt | AC | 24 ms | 3328 KB |
in19.txt | AC | 24 ms | 3328 KB |
in2.txt | AC | 24 ms | 3328 KB |
in20.txt | AC | 25 ms | 3328 KB |
in21.txt | AC | 22 ms | 1792 KB |
in22.txt | AC | 23 ms | 3328 KB |
in23.txt | AC | 1 ms | 256 KB |
in3.txt | AC | 24 ms | 3328 KB |
in4.txt | AC | 25 ms | 3328 KB |
in5.txt | AC | 25 ms | 3328 KB |
in6.txt | AC | 25 ms | 3328 KB |
in7.txt | AC | 24 ms | 3328 KB |
in8.txt | AC | 24 ms | 3328 KB |
in9.txt | AC | 24 ms | 3328 KB |
sample1.txt | AC | 1 ms | 256 KB |
sample2.txt | AC | 1 ms | 256 KB |
sample3.txt | AC | 1 ms | 256 KB |