답안 #64870

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
64870 2018-08-06T00:49:07 Z gs18115 조화행렬 (KOI18_matrix) C++14
100 / 100
515 ms 119632 KB
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
using namespace std;
const int INF=1e9;
const int MAXN=2e5+10;
struct matrix
{
    int x,y,z;
    matrix()
    {
        x=y=z=0;
    }
}mat[MAXN];
bool cmp1(matrix a,matrix b)
{
    return a.x<b.x;
}
bool cmp2(matrix a,matrix b)
{
    return a.y<b.y;
}
bool cmp3(matrix a,matrix b)
{
    return a.z<b.z;
}
set<pair<int,int> >S[MAXN];
bool fp(int x,int y,int k)
{
    set<pair<int,int> >::iterator it=S[k].lower_bound(make_pair(x,0));
    if(it==S[k].begin())
        return false;
    it--;
    return it->second<y;
}
void ap(int x,int y,int k)
{
    if(fp(x,y,k))
        return;
    while(true)
    {
        set<pair<int,int> >::iterator it=S[k].lower_bound(make_pair(x,0));
        if(it==S[k].end())
            break;
        else if(it->second>y)
            S[k].erase(it);
        else
            break;
    }
    S[k].insert(make_pair(x,y));
    return;
}
int M,N,i;
int maxi,s,e,mid;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>M>>N;
    for(i=0;i<N;i++)
        cin>>mat[i].x;
    for(i=0;i<N;i++)
        cin>>mat[i].y;
    if(M==2)
        for(i=0;i<N;i++)
            mat[i].z=mat[i].y;
    else
        for(i=0;i<N;i++)
            cin>>mat[i].z;
    sort(mat,mat+N,cmp2);
    for(i=0;i<N;i++)
        mat[i].y=i+1;
    sort(mat,mat+N,cmp3);
    for(i=0;i<N;i++)
        mat[i].z=i+1;
    sort(mat,mat+N,cmp1);
    ap(mat[0].y,mat[0].z,1);
    maxi=1;
    for(i=1;i<N;i++)
    {
        s=0;e=maxi;
        while(s<e)
        {
            mid=s+e+1>>1;
            if(fp(mat[i].y,mat[i].z,mid))
                s=mid;
            else
                e=mid-1;
        }
        if(s>=maxi)
            maxi=s+1;
        ap(mat[i].y,mat[i].z,s+1);
    }
    cout<<maxi;
    return 0;
}

Compilation message

matrix.cpp: In function 'int main()':
matrix.cpp:86:20: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
             mid=s+e+1>>1;
                 ~~~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 12152 KB Output is correct
2 Correct 22 ms 12152 KB Output is correct
3 Correct 24 ms 12320 KB Output is correct
4 Correct 20 ms 12376 KB Output is correct
5 Correct 20 ms 12376 KB Output is correct
6 Correct 25 ms 12708 KB Output is correct
7 Correct 20 ms 12708 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 12708 KB Output is correct
2 Correct 26 ms 12708 KB Output is correct
3 Correct 25 ms 12708 KB Output is correct
4 Correct 28 ms 12708 KB Output is correct
5 Correct 35 ms 12708 KB Output is correct
6 Correct 28 ms 12756 KB Output is correct
7 Correct 27 ms 12756 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 12152 KB Output is correct
2 Correct 22 ms 12152 KB Output is correct
3 Correct 24 ms 12320 KB Output is correct
4 Correct 20 ms 12376 KB Output is correct
5 Correct 20 ms 12376 KB Output is correct
6 Correct 25 ms 12708 KB Output is correct
7 Correct 20 ms 12708 KB Output is correct
8 Correct 168 ms 12756 KB Output is correct
9 Correct 172 ms 12756 KB Output is correct
10 Correct 166 ms 14420 KB Output is correct
11 Correct 135 ms 14420 KB Output is correct
12 Correct 192 ms 14420 KB Output is correct
13 Correct 216 ms 16980 KB Output is correct
14 Correct 167 ms 16980 KB Output is correct
15 Correct 133 ms 16980 KB Output is correct
16 Correct 170 ms 21716 KB Output is correct
17 Correct 209 ms 21716 KB Output is correct
18 Correct 159 ms 21716 KB Output is correct
19 Correct 184 ms 21716 KB Output is correct
20 Correct 191 ms 21716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 12708 KB Output is correct
2 Correct 26 ms 12708 KB Output is correct
3 Correct 25 ms 12708 KB Output is correct
4 Correct 28 ms 12708 KB Output is correct
5 Correct 35 ms 12708 KB Output is correct
6 Correct 28 ms 12756 KB Output is correct
7 Correct 27 ms 12756 KB Output is correct
8 Correct 253 ms 21716 KB Output is correct
9 Correct 291 ms 21716 KB Output is correct
10 Correct 244 ms 21716 KB Output is correct
11 Correct 277 ms 21740 KB Output is correct
12 Correct 269 ms 21740 KB Output is correct
13 Correct 226 ms 29456 KB Output is correct
14 Correct 283 ms 32028 KB Output is correct
15 Correct 268 ms 41816 KB Output is correct
16 Correct 232 ms 47484 KB Output is correct
17 Correct 301 ms 50400 KB Output is correct
18 Correct 384 ms 53444 KB Output is correct
19 Correct 232 ms 58800 KB Output is correct
20 Correct 358 ms 67724 KB Output is correct
21 Correct 227 ms 76588 KB Output is correct
22 Correct 335 ms 77048 KB Output is correct
23 Correct 301 ms 84972 KB Output is correct
24 Correct 214 ms 87704 KB Output is correct
25 Correct 311 ms 94980 KB Output is correct
26 Correct 515 ms 108840 KB Output is correct
27 Correct 241 ms 108840 KB Output is correct
28 Correct 318 ms 116392 KB Output is correct
29 Correct 296 ms 116392 KB Output is correct
30 Correct 301 ms 116392 KB Output is correct
31 Correct 400 ms 119632 KB Output is correct
32 Correct 302 ms 119632 KB Output is correct