Submission #1165344

#TimeUsernameProblemLanguageResultExecution timeMemory
11653448pete8Triangles (CEOI18_tri)C++20
100 / 100
24 ms2052 KiB
#include<iostream>
#include<stack>
#include<map>
#include<vector>
#include<string>
#include<cassert>
#include<unordered_map>
#include <queue>
#include <cstdint>
#include<cstring>
#include<limits.h>
#include<cmath>
#include<set>
#include<algorithm>
#include <iomanip>
#include<numeric>
#include<bitset>
#include "trilib.h"
using namespace std;
#define ll long long
#define f first
#define s second
#define pii pair<int,int>
#define ppii pair<int,pii>
#define vi vector<int>
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define F(n) for(int i=0;i<n;i++)
#define lb lower_bound
#define ub upper_bound
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);
#pragma GCC optimize ("03,unroll-lopps")
#define int long long
#define double long double
using namespace std;
const int mod=998244353,mxn=2e3+5,inf=1e18,minf=-1e18,lg=30;
//#undef int
int n,k,m,x,q;
void setIO(string name){		
	ios_base::sync_with_stdio(0); cin.tie(0);		
	freopen((name+".in").c_str(),"r",stdin);
	freopen((name+".out").c_str(),"w",stdout);
}
bool cmp(int a,int b){
	return (is_clockwise(1,a,b));
}
bool cmp2(int a,int b){
	return (is_clockwise(1,a,b));
}
int32_t main(){
	fastio
	int n=get_n();
	vector<int>L,R;
	for(int i=3;i<=n;i++){
		if(is_clockwise(1,2,i))R.pb(i);
		else L.pb(i);
	}
	sort(all(R),cmp);
	sort(all(L),cmp2);
	deque<int>RC={1,2},LC={2,1};
	vector<int>del(n+1,0);
	for(auto i:R){
		while(RC.size()>2&&is_clockwise(RC[RC.size()-2],i,RC.back()))RC.pop_back();
		RC.pb(i);
	}
	for(auto i:L){
		while(LC.size()>2&&is_clockwise(LC[LC.size()-2],i,LC.back()))LC.pop_back();
		LC.pb(i);
	}
	RC.pop_front();
	LC.pop_front();
	while(1){
		int yes=0;
		while(LC.size()>=2&&RC.size()>=1&&LC.size()+RC.size()>2&&is_clockwise(RC.back(),LC[1],LC[0])){
			LC.pop_front();
			yes=1;
		}
		while(RC.size()>=2&&LC.size()>=1&&LC.size()+RC.size()>2&&is_clockwise(RC[RC.size()-2],LC[0],RC.back())){
			RC.pop_back();
			yes=1;
		}
		if(!yes)break;
	}
	while(1){
		int yes=0;
		while(RC.size()>=2&&LC.size()>=1&&LC.size()+RC.size()>2&&is_clockwise(LC.back(),RC[1],RC[0])){
			RC.pop_front();
			yes=1;
		}
		while(LC.size()>=2&&RC.size()>=1&&LC.size()+RC.size()>2&&is_clockwise(LC[LC.size()-2],RC[0],LC.back())){
			LC.pop_back();
			yes=1;
		}
		if(!yes)break;
	}
	give_answer(RC.size()+LC.size());
}

/*
6 
1 1
4 3
2 2
1 4
5 1
3 2

7
8 6
1 1
2 5 	
4 10
9 5
3 6
2 5
6
*/

Compilation message (stderr)

tri.cpp:33:40: warning: bad option '-funroll-lopps' to pragma 'optimize' [-Wpragmas]
   33 | #pragma GCC optimize ("03,unroll-lopps")
      |                                        ^
tri.cpp:40:23: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
   40 | void setIO(string name){
      |                       ^
tri.cpp:45:21: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
   45 | bool cmp(int a,int b){
      |                     ^
tri.cpp:48:22: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
   48 | bool cmp2(int a,int b){
      |                      ^
tri.cpp:51:14: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
   51 | int32_t main(){
      |              ^
tri.cpp: In function 'void setIO(std::string)':
tri.cpp:42:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |         freopen((name+".in").c_str(),"r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tri.cpp:43:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |         freopen((name+".out").c_str(),"w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...