/ SB域 /

记录详情

Wrong Answer

foo.cc: In function 'int calc(int, int*)':
foo.cc:36:17: warning: operation on 'k' may be undefined [-Wsequence-point]
         else f[k=find(1,len,c[i])]=min(f[k],c[i]);
                ~^~~~~~~~~~~~~~~~~

自豪的采用 HydroJudge 进行评测(github.com/hydro-dev/HydroJudge)
正在同步测试数据,请稍后
{"receive":"2020-08-10T03:30:00.278Z","handle":"2020-08-10T03:30:00.278Z","cache_start":"2020-08-10T03:30:00.286Z","read_cases":"2020-08-10T03:30:01.983Z","judge":"2020-08-10T03:30:01.983Z","done":"2020-08-10T03:30:02.406Z"}
# 状态 耗时 内存占用
#1 Wrong Answer 读取到 2377 ,应为 154 2ms 1.375 MiB
#2 Wrong Answer 读取到 2609 ,应为 145 2ms 1.375 MiB
#3 Wrong Answer 读取到 1798 ,应为 153 2ms 1.375 MiB
#4 Wrong Answer 读取到 1798 ,应为 153 2ms 1.375 MiB
#5 Wrong Answer 读取到 1798 ,应为 153 2ms 1.375 MiB
#6 Wrong Answer 读取到 1798 ,应为 153 2ms 1.375 MiB
#7 Wrong Answer 读取到 61972 ,应为 771 16ms 2.508 MiB
#8 Wrong Answer 读取到 61972 ,应为 771 16ms 2.41 MiB
#9 Wrong Answer 读取到 61972 ,应为 771 16ms 2.457 MiB
#10 Wrong Answer 读取到 61972 ,应为 771 16ms 2.508 MiB

代码

#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;

int read()
{
    int x=0,f=1;char c=getchar();
    while (c<'0' || c>'9'){if (c=='-')f=-1;c=getchar();}
    while (c>='0'&&c<='9'){x=(x<<3)+(x<<1)+c-48;c=getchar();}
    return x*f;
}

const int MAXN=300005;
int n,k,cnt,ans;
int a[MAXN],b[MAXN],f[MAXN];

int find(int l,int r,int k)
{
    int mid;
    while (l<r)
    {
        mid=(l+r)>>1;
        if (f[mid]>=k)r=mid;
        else l=mid+1;
    }
    return l;
}

int calc(int n,int c[MAXN])
{
    memset(f,0,sizeof(f));
    int len=0,k;
    for (int i=1;i<=n;i++)
        if (c[i]>f[len])f[++len]=c[i];
        else f[k=find(1,len,c[i])]=min(f[k],c[i]);
    return len;
}

int main()
{
    n=read();k=read();
    for (int i=1;i<=n;i++) a[i]=read();
    cnt=0;
    for (int i=1;i<k;i++)
        if (a[i]<a[k])b[++cnt]=a[i];
    ans+=calc(cnt,b);
    cnt=0;
    for (int i=k+1;i<=n;i++)
        if (a[i]>a[k])b[++cnt]=a[i];
    ans+=calc(cnt,b);
    printf("%d\n",ans+1);
    return 0;
}

信息

递交者
类型
递交
题目
P1000 一个小问题
题目数据
下载
语言
C++
递交时间
2019-05-11 11:32:00
评测时间
2020-08-10 11:30:00
评测机
分数
0
总耗时
78ms
峰值内存
2.508 MiB