답안 #347175

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
347175 2021-01-12T07:37:00 Z cheetose 여별 열쇠 (JOI15_keys) C++17
0 / 100
9 ms 16236 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 1987654321
#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};

vector<Vi> V;
VPi vv,v[2005];
int a[2005];
int cnt[2005];
int d[2005][2005][2];
void dfs(int N,int p=-1){
	cnt[N]=1;
	for(auto [next,cost]:v[N]){
		if(next==p)continue;
		dfs(next,N);
		cnt[N]+=cnt[next];
	}
}
void dfs2(int N,int p=-1){
	if(p!=-1 && v[N].size()==1){
		d[N][1][1]=a[N];
		d[N][0][1]=-INF;
		return;
	}
	for(auto [next,cost]:v[N]){
		if(next==p)continue;
		dfs2(next,N);
		fup(i,1,cnt[N],1){
			d[N][i][0]=max(d[next][i][1],d[next][i][0]);
			d[N][i][1]=max(d[next][i-1][0]+a[N],d[next][i-1][1]+a[N]+cost);
		}
	}
}
void g(int N){
	if(v[N].empty()){
		cnt[N]=1;
		V.pb(Vi{0,a[N]});
		return;
	}
	dfs(N);
	dfs2(N);
	Vi VV;
	fup(i,0,cnt[N],1)VV.pb(max(d[N][i][0],d[N][i][1]));
	V.pb(VV);
}
int dd[2005][2005];
int go(int N,int K){
	if(N==V.size())return 0;
	int &ret=dd[N][K];
	if(~ret)return ret;
	ret=0;
	int n=min(K,(int)V[N].size()-1);
	fup(i,0,n,1){
		ret=max(ret,V[N][i]+go(N+1,K-i));
	}
	return ret;
}
int main() {
	int n,m,k;
	scanf("%d%d%d",&n,&m,&k);
	fup(i,1,n,1){
		int x,y;
		scanf("%d%d",&x,&y);
		vv.pb(mp(x,i));
		vv.pb(mp(y,-i));
	}
	sort(ALL(vv));
	int ans=vv[0].X+m-vv.back().X;
	fup(i,0,2*n-2,1){
		int c=vv[i+1].X-vv[i].X;
		if(vv[i].Y<0 && vv[i+1].Y<0){
			a[-vv[i+1].Y]+=c;
		}else if(vv[i].Y<0 && vv[i+1].Y>0){
			ans+=c;
		}else if(vv[i].Y>0 && vv[i+1].Y<0){
			if(vv[i].Y==-vv[i+1].Y)a[vv[i].Y]+=c;
			else{
				v[vv[i].Y].pb(mp(-vv[i+1].Y,c));
				v[-vv[i+1].Y].pb(mp(vv[i].Y,c));
			}
		}else{
			a[vv[i].Y]+=c;
		}
	}
	fup(i,1,n,1)if(!cnt[i] && v[i].size()<=1)g(i);
	MEM_1(dd);
	printf("%d\n",go(0,k)+ans);
}

Compilation message

keys.cpp: In function 'void dfs2(int, int)':
keys.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))
      |                              ^
keys.cpp:65:3: note: in expansion of macro 'fup'
   65 |   fup(i,1,cnt[N],1){
      |   ^~~
keys.cpp: In function 'void g(int)':
keys.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))
      |                              ^
keys.cpp:80:2: note: in expansion of macro 'fup'
   80 |  fup(i,0,cnt[N],1)VV.pb(max(d[N][i][0],d[N][i][1]));
      |  ^~~
keys.cpp: In function 'int go(int, int)':
keys.cpp:85:6: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   85 |  if(N==V.size())return 0;
      |     ~^~~~~~~~~~
keys.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))
      |                              ^
keys.cpp:90:2: note: in expansion of macro 'fup'
   90 |  fup(i,0,n,1){
      |  ^~~
keys.cpp: In function 'int main()':
keys.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))
      |                              ^
keys.cpp:98:2: note: in expansion of macro 'fup'
   98 |  fup(i,1,n,1){
      |  ^~~
keys.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))
      |                              ^
keys.cpp:106:2: note: in expansion of macro 'fup'
  106 |  fup(i,0,2*n-2,1){
      |  ^~~
keys.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))
      |                              ^
keys.cpp:122:2: note: in expansion of macro 'fup'
  122 |  fup(i,1,n,1)if(!cnt[i] && v[i].size()<=1)g(i);
      |  ^~~
keys.cpp:97:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   97 |  scanf("%d%d%d",&n,&m,&k);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~
keys.cpp:100:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  100 |   scanf("%d%d",&x,&y);
      |   ~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 16108 KB Output is correct
2 Incorrect 9 ms 16236 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 16108 KB Output is correct
2 Incorrect 9 ms 16236 KB Output isn't correct
3 Halted 0 ms 0 KB -