Submission #1221344
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 7;
int dp[N][2];
int res[N];
int main()
{
#ifdef ONPC
freopen("a.in", "r", stdin);
//freopen("a.out", "w", stdout);
#else
//freopen("a.in", "r", stdin);
//freopen("a.out", "w", stdout);
#endif
int n;
scanf("%d", &n);
vector <int> a(n);
for (int i = 0; i < n; i++)
{
scanf("%d", &a[i]);
}
dp[n - 1][0] = dp[n - 1][1] = 1;
for (int i = n - 2; i >= 0; i--)
{
if (a[i] == a[i + 1])
{
dp[i][0] = dp[i + 1][0] + 1;
dp[i][1] = dp[i + 1][1] + 1;
}
else if (a[i] > a[i + 1])
{
dp[i][0] = dp[i + 1][0] + 1;
}
else
{
dp[i][1] = dp[i + 1][1] + 1;
}
}
for (int i = 0; i <= n; i++)
{
res[i] = 1e9;
}
res[0] = 0;
for (int i = 0; i < n; i++)
{
res[i + dp[i][0]] = min(res[i + dp[i][0]], res[i] + 1);
res[i + dp[i][1]] = min(res[i + dp[i][1]], res[i] + 1);
}
printf("%d\n", res[n]);
}
Submission Info
Submission Time |
|
Task |
A - Sorted Arrays |
User |
300iq |
Language |
C++14 (GCC 5.4.1) |
Score |
0 |
Code Size |
1155 Byte |
Status |
WA |
Exec Time |
14 ms |
Memory |
1792 KB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:21:20: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &n);
^
./Main.cpp:25:27: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &a[i]);
^
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
0 / 300 |
Status |
|
|
Set Name |
Test Cases |
Sample |
sample_01.txt, sample_02.txt, sample_03.txt |
All |
sample_01.txt, sample_02.txt, sample_03.txt, sample_01.txt, sample_02.txt, sample_03.txt, subtask_1_01.txt, subtask_1_02.txt, subtask_1_03.txt, subtask_1_04.txt, subtask_1_05.txt, subtask_1_06.txt, subtask_1_07.txt, subtask_1_08.txt, subtask_1_09.txt, subtask_1_10.txt, subtask_1_11.txt |
Case Name |
Status |
Exec Time |
Memory |
sample_01.txt |
AC |
1 ms |
256 KB |
sample_02.txt |
WA |
1 ms |
256 KB |
sample_03.txt |
AC |
1 ms |
256 KB |
subtask_1_01.txt |
WA |
9 ms |
1152 KB |
subtask_1_02.txt |
AC |
7 ms |
1024 KB |
subtask_1_03.txt |
WA |
5 ms |
768 KB |
subtask_1_04.txt |
WA |
14 ms |
1792 KB |
subtask_1_05.txt |
AC |
13 ms |
1792 KB |
subtask_1_06.txt |
WA |
14 ms |
1792 KB |
subtask_1_07.txt |
WA |
14 ms |
1792 KB |
subtask_1_08.txt |
AC |
13 ms |
1792 KB |
subtask_1_09.txt |
WA |
14 ms |
1792 KB |
subtask_1_10.txt |
AC |
1 ms |
256 KB |
subtask_1_11.txt |
AC |
1 ms |
256 KB |