답안 #800151

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
800151 2023-08-01T10:57:39 Z lollipop 식물 비교 (IOI20_plants) C++17
14 / 100
4000 ms 9512 KB
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define ll long long
#define pb push_back
#define s second
#define f first
#define pf push_front
#define inf 100000000000000000
#define bitebi __builtin_popcountll
#define FOR( i , n ) for( int i = 0 ; i < n ; i ++ )
#define YES cout <<"YES\n"
#define NO cout << "NO\n"
#define debug cout << "Here Fine" << endl ;
#define pr pair < int , int >
#define fbo find_by_order // returns iterator
#define ook order_of_key // returns strictly less numbers than key
using namespace std ;
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
const double Pi=acos(-1.0);
const double EPS=1E-8;
const int mod =  1000000007 ;
const int mod1 = 998244353 ;
const int NN = 2e5 + 10 ;
mt19937 R(time(0));
map < int , int > ma , ma1 ;

#include "plants.h"

int tt = 2 ;
vector < int > v ; 
int case1( int x , int y ){
    int n = v.size() ;
    int cc = 0 ;
    if( x < y ){
        if( x == 0 && y != n - 1 && y != 1 ) return 0 ;
        if( x == 0 && y == n - 1 ){
           if( v[ y ] == 0 ) return -1 ;
           else return 1 ;
        }
        if( x + 1 != y ) return 0 ;
        if( v[ x ] == 0 ) return 1 ;
        else return -1 ;
    }
    swap( x , y ) ;
        if( x == 0 && y != n - 1 && y != 1 ) return 0 ;
        if( x == 0 && y == n - 1 ){
           if( v[ y ] == 0 ) return 1 ;
           else return -1 ;
        }
        if( x + 1 != y ) return 0 ;
        if( v[ x ] == 0 ) return -1 ;
        else return 1 ;  
}
int a[ 300000 ] ;
int been[ 300000 ] ;
int case2( int x , int y ){
    if( a[ x ] < a[ y ] )return -1 ;
    else return 1 ;

}
void init(int k, std::vector<int> r){
     tt = k ; 
     if( k == 2 ){
       v = r ; return ;
     }     
     int cnt = 0 ;
     int nn = r.size() ;
     FOR( i , nn ) been[ i ] = 0 ;
     int cur = nn - 1 ; 
     while( true ){
        if( cnt == nn - 1 ){
            FOR( i , nn ) if( been[ i ] == 0 ){
                a[ i ] = 0 ; break ;
            }
            break ; 
        }
        vector < int > v ;
        FOR( i , nn ){
            if( r[ i ] == 0 ) v.pb( i ) ; 
        }
        int x = v[ 0 ] ;
        if( v.size() != 1 ){
           pair < int , int > mx ;
           mx.f = -1 ;
           FOR( i , v.size() ){
             if( i == 0 ){
              int cur = v[ i ] + ( nn - 1 - v[ v.size() - 1 ] ) ;
              if( cur > mx.f ){
                mx = { cur , v[ i ] } ; 
              }
             }
             else{
              int cur = v[ i ] - v[ i - 1 ] - 1 ;
              if( cur > mx.f ){
                mx = { cur , v[ i ] } ; 
              }
             }
           }
           x = mx.s ; 
        }
        been[ x ] = 1 ;
        a[ x ] = cur ; 
        r[ x ] = -1 ; 
        int pos = x - 1 ;
        int kk = k - 1 ; 
        while( kk -- ){           
            if( pos < 0 ) pos = nn - 1 ;
           r[ pos ] -- ;
           pos -- ;

        }
        cnt ++ ; cur -- ;
     }
}

int compare_plants(int x, int y){
    if( tt == 2 ) return case1( x , y ) ;
    else return case2( x , y ) ;
}


// static int n, k, q;
// static std::vector<int> r;
// static std:: vector<int> x;
// static std:: vector<int> y;
// static std:: vector<int> answer;
// int main() {
// 	assert(scanf("%d%d%d", &n, &k, &q) == 3);
// 	r.resize(n);
// 	answer.resize(q);
// 	for (int i = 0; i < n; i++) {
// 		int value;
// 		assert(scanf("%d", &value) == 1);
// 		r[i] = value;
// 	}
// 	x.resize(q);
// 	y.resize(q);
// 	for (int i = 0; i < q; i++) {
// 		assert(scanf("%d%d", &x[i], &y[i]) == 2);
// 	}

// 	init(k, r);
// 	for (int i = 0; i < q; i++) {
// 		answer[i] = compare_plants(x[i], y[i]);
// 	}


// 	for (int i = 0; i < q; i++) {
// 		printf("%d\n", answer[i]);
// 	}


// 	return 0;
// }

Compilation message

plants.cpp: In function 'int case1(int, int)':
plants.cpp:39:9: warning: unused variable 'cc' [-Wunused-variable]
   39 |     int cc = 0 ;
      |         ^~
plants.cpp: In function 'void init(int, std::vector<int>)':
plants.cpp:12:41: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 | #define FOR( i , n ) for( int i = 0 ; i < n ; i ++ )
......
   91 |            FOR( i , v.size() ){
      |                 ~~~~~~~~~~~~             
plants.cpp:91:12: note: in expansion of macro 'FOR'
   91 |            FOR( i , v.size() ){
      |            ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Incorrect 1 ms 212 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 5 ms 452 KB Output is correct
7 Correct 124 ms 5068 KB Output is correct
8 Correct 2 ms 424 KB Output is correct
9 Correct 5 ms 452 KB Output is correct
10 Correct 123 ms 5028 KB Output is correct
11 Correct 126 ms 5032 KB Output is correct
12 Correct 115 ms 5196 KB Output is correct
13 Correct 130 ms 5028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 5 ms 452 KB Output is correct
7 Correct 124 ms 5068 KB Output is correct
8 Correct 2 ms 424 KB Output is correct
9 Correct 5 ms 452 KB Output is correct
10 Correct 123 ms 5028 KB Output is correct
11 Correct 126 ms 5032 KB Output is correct
12 Correct 115 ms 5196 KB Output is correct
13 Correct 130 ms 5028 KB Output is correct
14 Correct 1241 ms 5592 KB Output is correct
15 Execution timed out 4056 ms 9512 KB Time limit exceeded
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 51 ms 3076 KB Output is correct
4 Execution timed out 4067 ms 8980 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 0 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 0 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Incorrect 1 ms 212 KB Output isn't correct
6 Halted 0 ms 0 KB -