답안 #150144

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
150144 2019-09-01T07:48:01 Z 20190901(#3597, tongnamuu, jf297, upple1) 십자가 놓기 (FXCUP4_cross) C++17
0 / 100
279 ms 6636 KB
#include "cross.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
pair<int, int> arr[200000];
int it[200000], ot[200000];
int n;

int update(int st[], int idx, int v, int p, int x, int y)
{
    if(idx<x || idx>y) return st[p];
    if(x==y) return st[p]=v;
    int mid=x+y>>1;
    return st[p]=min(update(st, idx, v, p<<1, x, mid), update(st, idx, v, (p<<1)+1, mid+1, y));
}

long long SelectCross(int K, std::vector<int> I, std::vector<int> O)
{
    n=I.size();
	memset(it, 0x3f3f3f3f, sizeof(it));
	memset(ot, 0x3f3f3f3f, sizeof(ot));
    for(int i=0; i<n; i++)
    {
        arr[i]={O[i], I[i]};
    }

    sort(arr, arr+n);
    for(int i=0; i<K; i++)
    {
        update(ot, i, arr[i].first, 1, 0, n);
        update(it, i, arr[i].second, 1, 0, n);
    }

    ll ans=0;
    for(int i=0; i<n; i++)
    {
        int isize=it[1], osize=ot[1];
		
        ans=max(ans, ll(osize)*osize-ll(osize-isize)*(osize-isize));
		// cout<<ans<<' ';
        update(ot, i, 1e9, 1, 0, n);
        update(it, i, 1e9, 1, 0, n);
        update(ot, (i+K)%n, arr[(i+K)%n].first, 1, 0, n);
        update(it, (i+K)%n, arr[(i+K)%n].second, 1, 0, n);
    }

	return ans;
}

Compilation message

cross.cpp: In function 'int update(int*, int, int, int, int, int)':
cross.cpp:13:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     int mid=x+y>>1;
             ~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 1920 KB Output is correct
2 Correct 6 ms 1920 KB Output is correct
3 Correct 6 ms 1792 KB Output is correct
4 Correct 7 ms 1920 KB Output is correct
5 Correct 19 ms 2304 KB Output is correct
6 Incorrect 279 ms 6636 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 1920 KB Output is correct
2 Correct 6 ms 1920 KB Output is correct
3 Correct 6 ms 1792 KB Output is correct
4 Correct 7 ms 1920 KB Output is correct
5 Correct 19 ms 2304 KB Output is correct
6 Incorrect 279 ms 6636 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 1920 KB Output is correct
2 Correct 6 ms 1920 KB Output is correct
3 Correct 6 ms 1792 KB Output is correct
4 Correct 7 ms 1920 KB Output is correct
5 Correct 19 ms 2304 KB Output is correct
6 Incorrect 279 ms 6636 KB Output isn't correct
7 Halted 0 ms 0 KB -