답안 #346460

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
346460 2021-01-09T20:16:57 Z cheetose 별자리 (JOI12_constellation) C++17
90 / 100
81 ms 13708 KB
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define y0 y12
#define y1 y22
#define INF 987654321
#define PI 3.141592653589793238462643383279502884
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset((a),0,sizeof(a))
#define MEM_1(a) memset((a),-1,sizeof(a))
#define ALL(a) a.begin(),a.end()
#define COMPRESS(a) sort(ALL(a));a.resize(unique(ALL(a))-a.begin())
#define SYNC ios_base::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<db, db> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<double> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<int,int,int,int> iiii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
const int MOD = 1000000007;
ll POW(ll a, ll b, ll MMM=MOD) {ll ret=1; for(;b;b>>=1,a=(a*a)%MMM)if(b&1)ret=(ret*a)% MMM; return ret; }
int dx[] = { 0,1,0,-1,1,1,-1,-1 }, dy[] = { 1,0,-1,0,1,-1,1,-1 };
int ddx[]={2,2,-2,-2,1,1,-1,-1},ddy[]={1,-1,1,-1,2,-2,2,-2};

struct point {
	int x, y, p, q, c;
	point() : point(0, 0) {}
	point(int xx, int yy) : x(xx),y(yy),p(0),q(0),c(0){}
}p[100000];
bool f(point p1, point p2)
{
	if (1LL * p1.q*p2.p != 1LL * p1.p*p2.q)return 1LL * p1.q*p2.p < 1LL * p1.p*p2.q;
	if (p1.y != p2.y) return p1.y < p2.y;
	return p1.x < p2.x;
}
point operator - (point &p1)
{
	int xx = -p1.x, yy = -p1.y;
	return point(xx, yy);
}
point operator - (point &p1, point &p2)
{
	int xx = p1.x - p2.x, yy = p1.y - p2.y;
	return point(xx, yy);
}
bool ccw(int i, int j, int k)
{
	if (1LL * (p[j] - p[i]).x*(p[k] - p[j]).y - 1LL * (p[j] - p[i]).y*(p[k] - p[j]).x > 0)return 1;
	return 0;
}
Vi a;
int d[100000][2][3];
int go(int N,int c,int k){
	if(k==3)return 0;
	int &ret=d[N][c][k];
	if(~ret)return ret;
	ret=0;
	if(a[N]==2-c)return ret;
	if(N==a.size()-1)return ret=1;
	ret=(go(N+1,c,k)+go(N+1,1-c,k+1))%MOD;
	return ret;
}
int main() {
	MEM_1(d);
	int n;
	scanf("%d", &n);
	int tt=0;
	int q=0,w=0;
	for (int i = 0; i < n; i++)
	{
		int x, y, c;
		scanf("%d%d%d", &x, &y, &c);
		p[i] = point(x, y);
		p[i].c=c;
		if(c==0)tt++;
		if(c==1)q=1;
		if(c==2)w=1;
	}
	if(n==2)return !printf("%d\n",1<<tt);
	sort(p, p + n, f);
	for (int i = 1; i < n; i++)
	{
		p[i].p = p[i].x - p[0].x;
		p[i].q = p[i].y - p[0].y;
	}
	sort(p + 1, p + n, f);
	Vi hull;
	hull.push_back(0);
	hull.push_back(1);
	int next = 2;
	while (next < n)
	{
		while (hull.size() >= 2)
		{
			int first = hull.back();
			hull.pop_back();
			int second = hull.back();
			if (ccw(second, first, next))
			{
				hull.push_back(first);
				break;
			}
		}
		hull.push_back(next++);
	}
	for(int i:hull){
		if(p[i].c==0)tt--;
		a.pb(p[i].c);
	}
	int ans=(go(0,0,0)+go(0,1,0))%MOD;
	fup(i,1,tt,1)ans=(ans<<1)%MOD;
	ans=(ans+MOD-(1-q)-(1-w))%MOD;
	printf("%d\n",ans);
}

Compilation message

constellation.cpp: In function 'int go(int, int, int)':
constellation.cpp:77:6: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   77 |  if(N==a.size()-1)return ret=1;
      |     ~^~~~~~~~~~~~
constellation.cpp: In function 'int main()':
constellation.cpp:10:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
      |                              ^
constellation.cpp:129:2: note: in expansion of macro 'fup'
  129 |  fup(i,1,tt,1)ans=(ans<<1)%MOD;
      |  ^~~
constellation.cpp:84:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   84 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
constellation.cpp:90:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   90 |   scanf("%d%d%d", &x, &y, &c);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4588 KB Output is correct
2 Correct 3 ms 4588 KB Output is correct
3 Correct 3 ms 4588 KB Output is correct
4 Correct 3 ms 4588 KB Output is correct
5 Incorrect 3 ms 4608 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4588 KB Output is correct
2 Correct 3 ms 4588 KB Output is correct
3 Correct 3 ms 4588 KB Output is correct
4 Correct 3 ms 4716 KB Output is correct
5 Correct 3 ms 4588 KB Output is correct
6 Correct 3 ms 4588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4588 KB Output is correct
2 Correct 3 ms 4588 KB Output is correct
3 Correct 4 ms 4588 KB Output is correct
4 Correct 3 ms 4588 KB Output is correct
5 Correct 3 ms 4588 KB Output is correct
6 Correct 4 ms 4588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4588 KB Output is correct
2 Correct 3 ms 4588 KB Output is correct
3 Correct 3 ms 4608 KB Output is correct
4 Correct 3 ms 4588 KB Output is correct
5 Correct 3 ms 4588 KB Output is correct
6 Correct 3 ms 4588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4588 KB Output is correct
2 Correct 3 ms 4588 KB Output is correct
3 Correct 4 ms 4588 KB Output is correct
4 Correct 3 ms 4588 KB Output is correct
5 Correct 3 ms 4588 KB Output is correct
6 Correct 3 ms 4588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4588 KB Output is correct
2 Correct 7 ms 4992 KB Output is correct
3 Correct 6 ms 5100 KB Output is correct
4 Correct 6 ms 5100 KB Output is correct
5 Correct 6 ms 4716 KB Output is correct
6 Correct 4 ms 4588 KB Output is correct
7 Correct 6 ms 4716 KB Output is correct
8 Correct 6 ms 4716 KB Output is correct
9 Correct 6 ms 5100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4588 KB Output is correct
2 Correct 79 ms 4588 KB Output is correct
3 Correct 4 ms 4588 KB Output is correct
4 Correct 80 ms 6764 KB Output is correct
5 Correct 78 ms 13544 KB Output is correct
6 Correct 4 ms 4588 KB Output is correct
7 Correct 7 ms 5100 KB Output is correct
8 Correct 7 ms 5100 KB Output is correct
9 Correct 7 ms 5100 KB Output is correct
10 Correct 80 ms 13672 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4588 KB Output is correct
2 Correct 74 ms 4588 KB Output is correct
3 Correct 4 ms 4588 KB Output is correct
4 Correct 77 ms 6764 KB Output is correct
5 Correct 75 ms 13672 KB Output is correct
6 Correct 4 ms 4588 KB Output is correct
7 Correct 7 ms 5100 KB Output is correct
8 Correct 6 ms 5100 KB Output is correct
9 Correct 6 ms 5100 KB Output is correct
10 Correct 79 ms 13672 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4588 KB Output is correct
2 Correct 77 ms 4588 KB Output is correct
3 Correct 80 ms 11496 KB Output is correct
4 Correct 80 ms 11496 KB Output is correct
5 Correct 75 ms 11496 KB Output is correct
6 Correct 4 ms 4588 KB Output is correct
7 Correct 7 ms 5100 KB Output is correct
8 Correct 7 ms 5100 KB Output is correct
9 Correct 7 ms 5100 KB Output is correct
10 Correct 80 ms 13544 KB Output is correct
11 Correct 79 ms 13708 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4588 KB Output is correct
2 Correct 75 ms 4804 KB Output is correct
3 Correct 76 ms 4588 KB Output is correct
4 Correct 81 ms 13544 KB Output is correct
5 Correct 74 ms 13544 KB Output is correct
6 Correct 75 ms 13672 KB Output is correct
7 Correct 7 ms 5100 KB Output is correct
8 Correct 6 ms 5100 KB Output is correct
9 Correct 6 ms 5100 KB Output is correct
10 Correct 42 ms 9068 KB Output is correct