Submission #1221130
Source Code Expand
//Code by Lucida
#include<bits/stdtr1c++.h>
typedef long long int64;
namespace IO {
#ifdef OI
const int IN=1e7;
char in[IN],*ip=in,*ie=in;
#define getchar() ( (ip==ie && (ie=(ip=in)+fread(in,1,IN,stdin),ip==ie))?EOF:*ip++ )
#endif
struct Ist {
template <class T> Ist &operator >>(T &x);
template <class T> Ist &operator >>(T *x);
operator bool() const {return feof(stdin);}
}is;
template <class T> Ist &Ist::operator >>(T &x) {
static bool f;static char ch;
for(f=0,ch=0;ch<'0' || '9'<ch;ch=getchar()) f|=ch=='-';
for(x=0;'0'<=ch && ch<='9';ch=getchar()) (x*=10)+=ch-'0';
x=f?-x:x;
return *this;
}
template <class T> Ist &Ist::operator >>(T *x) {
while(*x=getchar(),(*x==' ' || *x=='\r' || *x=='\n' || *x==EOF));
x++;
while(*x=getchar(),(*x!=' ' && *x!='\r' && *x!='\n' && *x!=EOF))
x++;
*x=0;
return *this;
}
template <> Ist &Ist::operator >>(double &x) {
scanf("%lf",&x);
return *this;
}
template <> Ist &Ist::operator >>(char &x) {
while(x=getchar(),x=='\n' || x=='\r' || x==' ');
return *this;
}
#ifdef OO
const int OUT=1e7;
char out[OUT],*op=out,*oe=out+OUT;
#define flush() (fwrite(out,1,op-out,stdout))
#define putchar(x) ((op==oe?(flush(),*op++):*op++)=(x) )
#endif
struct Ost {
char doubleFormat[10];
Ost() {
sprintf(doubleFormat,"%%lf");
}
#ifdef OO
~Ost() {
flush();
}
#endif
void precision(const int &a) {
sprintf(doubleFormat,"%%.%dlf",a);
}
template <class T> Ost &operator <<(T x);
template <class T> Ost &operator <<(T *x);
}os;
template <class T> Ost &Ost::operator <<(T x) {
if(!x)
putchar('0');
else {
if(x<0) putchar('-'),x=-x;
static char stack[30]={0};
char *top=stack;
for(;x;x/=10) *++top=x%10+'0';
while(*top) putchar(*top--);
}
return *this;
}
template <class T> Ost &Ost::operator <<(T* x) {
while(*x) putchar(*x++);
return *this;
}
template <> Ost &Ost::operator <<(double x) {
printf(doubleFormat,x);
return *this;
}
template <> Ost &Ost::operator <<(char x) {
putchar(x);
return *this;
}
}
template <class T> inline bool chkmx(T &a,const T &b) {return a<b?a=b,1:0;}
template <class T> inline bool chkmn(T &a,const T &b) {return a>b?a=b,1:0;}
template <class T,class C> inline T &operator +=(T &a,const C &b) {return a=a+b;}
template <class T,class C> inline T &operator -=(T &a,const C &b) {return a=a-b;}
template <class T,class C> inline T &operator *=(T &a,const C &b) {return a=a*b;}
template <class T,class C> inline T &operator /=(T &a,const C &b) {return a=a/b;}
using IO::is;
using IO::os;
#define alloc(T,c) (T*)malloc((c)*sizeof(T))
#define pass void(0)
#define import using std::
#define array std::vector
const int MAXN=1e5+11;
int main() {
// freopen("input","r",stdin);
int n;
static int a[MAXN];
is>>n;
for(int i=1;i<=n;++i) {
is>>a[i];
}
static int f[MAXN][2];//0降序 1升序
memset(f,31,sizeof(f));
f[1][0]=f[1][1]=1;
for(int i=2;i<=n;++i) {
if(a[i-1]<=a[i]) {
chkmn(f[i][1],f[i-1][1]);
}
if(a[i-1]>=a[i]) {
chkmn(f[i][0],f[i-1][0]);
}
int minv=std::min(f[i-1][0],f[i-1][1]);
chkmn(f[i][0],minv+1);
chkmn(f[i][1],minv+1);
}
os<<std::min(f[n][0],f[n][1])<<'\n';
return 0;
}
Submission Info
Submission Time
2017-04-15 21:06:11+0900
Task
A - Sorted Arrays
User
Lucida
Language
C++14 (GCC 5.4.1)
Score
300
Code Size
3321 Byte
Status
AC
Exec Time
10 ms
Memory
1408 KB
Compile Error
./Main.cpp: In member function ‘IO::Ist& IO::Ist::operator>>(T&) [with T = double]’:
./Main.cpp:31:18: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%lf",&x);
^
Judge Result
Set Name
Sample
All
Score / Max Score
0 / 0
300 / 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
1024 KB
sample_02.txt
AC
1 ms
1024 KB
sample_03.txt
AC
1 ms
1024 KB
subtask_1_01.txt
AC
7 ms
1280 KB
subtask_1_02.txt
AC
5 ms
1152 KB
subtask_1_03.txt
AC
4 ms
1152 KB
subtask_1_04.txt
AC
10 ms
1408 KB
subtask_1_05.txt
AC
10 ms
1408 KB
subtask_1_06.txt
AC
10 ms
1408 KB
subtask_1_07.txt
AC
10 ms
1408 KB
subtask_1_08.txt
AC
10 ms
1408 KB
subtask_1_09.txt
AC
10 ms
1408 KB
subtask_1_10.txt
AC
1 ms
1024 KB
subtask_1_11.txt
AC
1 ms
1024 KB