답안 #25602

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
25602 2017-06-23T07:33:21 Z 윤교준(#1076) 한자 끝말잇기 (JOI14_kanji) C++11
0 / 100
212 ms 17144 KB
#include "Annalib.h"
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <string>
#define pb push_back
#define sz(V) ((int)(V).size())
#define allv(V) ((V).begin()),((V).end())
#define befv(V) ((V)[(sz(V)-2)])
#define sorv(V) sort(allv(V))
#define revv(V) reverse(allv(V))
#define univ(V) (V).erase(unique(allv(V)),(V).end())
#define clv(V) (V).clear()
#define upmin(a,b) (a)=min((a),(b))
#define upmax(a,b) (a)=max((a),(b))
#define rb(x) ((x)&(-(x)))
#define INF (1100000099)
#define INFLL (3300000000000000099ll)
#define MAXN (305)
#define MAXM (90005)
#define MAXQ (65)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
static int uptwo[MAXN];
static inline void writeNum(int N, int Cnt) {
	for(int i = 0; i < Cnt; i++) Tap((N & (1<<i)) ? 1 : 0);
	//printf("WRITENUM %d %d\n", N, Cnt);
}

static int A[MAXM], B[MAXM];
static ll C[MAXM];
static int S[MAXQ], T[MAXQ];
static int U[5];
static int N, M, Q, K;

static ll d[MAXN][MAXN];

static ll getDist(int S, int E, int QN) {
	if(5 == QN) return d[S][E];
	return d[S][A[U[0]]] + C[U[QN]] + d[B[U[QN]]][E];
}
static int querycountF(const vector<int>& VQ, vector<int>& VQA, vector<int>& VQB, int QA, int QB) {
	clv(VQA); clv(VQB); for(int v : VQ) {
		if(getDist(S[v], T[v], QA) <= getDist(S[v], T[v], QB)) {
			VQA.pb(v);
		} else {
			VQB.pb(v);
		}
	}
}
static void process() {
	vector<int> VQ[6]; for(int i = 0; i < Q; i++) VQ[0].pb(i);
	vector<int> VA, VB; // j, i
	for(int i = 1; i <= 5; i++) {
		for(int j = 0; j < i; j++) {
			if((i < 5 && K <= i) || (j < 5 && K <= j)) continue;
			querycountF(VQ[j], VA, VB, j, i);
			//printf("TRY TO WRITE %d %d : %d %d\n", j, i, sz(VQ[j]), uptwo[sz(VQ[j])]);
			writeNum(sz(VA), uptwo[sz(VQ[j])]);
			swap(VQ[j], VA); for(int v : VB) VQ[i].pb(v);
		}
	}
	/*for(int i = 0; i <= 5; i++) {
		printf("QUERIES %d\n", i);
		for(int v : VQ[i]) printf("%d ", v); puts("");
	}*/
}
void Anna(int _N, int _M, int _A[], int _B[], long long _C[], int _Q, int _S[], int _T[], int _K, int _U[]) {
	uptwo[0] = 1; for(int i = 1; i <= MAXQ; i++) uptwo[i] = uptwo[i/2]+1;
	for(int i = 1; i <= MAXQ; i++) uptwo[i]--;
	N = _N; M = _M; Q = _Q; K = _K;
	for(int i = 0; i < M; i++) { A[i] = _A[i]; B[i] = _B[i]; C[i] = _C[i]; }
	for(int i = 0; i < Q; i++) { S[i] = _S[i]; T[i] = _T[i]; }
	for(int i = 0; i < K; i++) U[i] = _U[i];
	for(int i = 0; i < N; i++) fill(d[i], d[i]+MAXN, INFLL);
	for(int i = 0; i < N; i++) d[i][i] = 0;
	for(int i = 0; i < M; i++) d[A[i]][B[i]] = C[i];
	for(int i = 0; i < K; i++) d[A[U[i]]][B[U[i]]] = INFLL;
	for(int k = 0; k < N; k++) for(int i = 0; i < N; i++) for(int j = 0; j < N; j++)
		upmin(d[i][j], d[i][k] + d[k][j]);
	process();
}
#include "Brunolib.h"
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <string>
#define pb push_back
#define sz(V) ((int)(V).size())
#define allv(V) ((V).begin()),((V).end())
#define befv(V) ((V)[(sz(V)-2)])
#define sorv(V) sort(allv(V))
#define revv(V) reverse(allv(V))
#define univ(V) (V).erase(unique(allv(V)),(V).end())
#define clv(V) (V).clear()
#define upmin(a,b) (a)=min((a),(b))
#define upmax(a,b) (a)=max((a),(b))
#define rb(x) ((x)&(-(x)))
#define INF (1100000099)
#define INFLL (3300000000000000099ll)
#define MAXN (305)
#define MAXM (90005)
#define MAXQ (65)
#define MAXL (1005)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
static int uptwo[MAXN];

static int A[MAXM], B[MAXM];
static ll C[MAXM];
static int S[MAXQ], T[MAXQ];
static int U[5];
static int X[MAXL]; static int Xn = 0;
static int N, M, Q, K, L;

static vector<int> AnsPath[MAXQ];
static vector<int> VQ[6];
static ll d[MAXN][MAXN];
static ll rawd[MAXN][MAXN];
static int rawidx[MAXN][MAXN];

static inline int readBit() { return X[Xn++]; }
static inline int readNum(int Cnt) {
	int ret = 0;
	for(int i = 0; i < Cnt; i++) ret += readBit() * (1<<i);
	//printf("READNUM %d %d\n", ret, Cnt);
	return ret;
}
static void splitqueryF(const vector<int>& VQ, vector<int>& VA, vector<int>& VB, const int QA, const int QB, const int cnt) {
	clv(VA); clv(VB);
	if(5 == QB) {
		vector<pli> V;
		for(int v : VQ) V.pb({d[S[v]][A[U[0]]] + C[U[v]] - d[S[v]][T[v]], v});
		sorv(V);
		for(int i = 0; i < cnt; i++) VA.pb(V[i].second);
		for(int i = cnt; i < sz(V); i++) VB.pb(V[i].second);
	} else {
		vector<pli> V;
		for(int v : VQ) V.pb({C[U[QA]] - C[U[QB]], v});
		sorv(V);
		for(int i = 0; i < cnt; i++) VA.pb(V[i].second);
		for(int i = cnt; i < sz(V); i++) VB.pb(V[i].second);
	}
}
static void process() {
	for(int i = 0; i < Q; i++) VQ[0].pb(i);
	vector<int> VA, VB; // j, i
	for(int i = 1; i <= 5; i++) {
		for(int j = 0; j < i; j++) { // j, i
			if((i < 5 && K <= i) || (j < 5 && K <= j)) continue;
			const int ret = readNum(uptwo[sz(VQ[j])]);
			splitqueryF(VQ[j], VA, VB, j, i, ret);
			swap(VQ[j], VA); for(int v : VB) VQ[i].pb(v);
		}
	}
}
static void getPath(vector<int>& V, int S, int E) {
	if(S == E) return;
	if(d[S][E] == rawd[S][E] && -1 != rawidx[S][E]) { V.pb(rawidx[S][E]); return; }
	for(int i = 0; i < N; i++) {
		if(i == S || i == E) continue;
		if(d[S][E] == d[S][i] + d[i][E]) {
			getPath(V, S, i); getPath(V, i, E);
			return;
		}
	}
	//printf("GETPATH FUCKED %d %d\n", S, E);
}
static void getAns() {
	for(int i = 0; i <= 5; i++) {
		for(int v : VQ[i]) {
			vector<int> &V = AnsPath[v];
			//printf("GETANS %d : %d\n", v, i);
			if(5 == i) {
				getPath(V, S[v], T[v]);
			} else {
				getPath(V, S[v], A[U[i]]);
				V.pb(U[i]);
				getPath(V, B[U[i]], T[v]);
			}
		}
	}
}
static void printAns() {
	for(int i = 0; i < Q; i++) {
		for(int v : AnsPath[i]) Answer(v);
		Answer(-1);
	}
}
void Bruno(int _N, int _M, int _A[], int _B[], long long _C[]
		 , int _Q, int _S[], int _T[], int _K, int _U[], int _L, int _X[]) {
	uptwo[0] = 1; for(int i = 1; i <= MAXQ; i++) uptwo[i] = uptwo[i/2]+1;
	for(int i = 1; i <= MAXQ; i++) uptwo[i]--;
	N = _N; M = _M; Q = _Q; K = _K; L = _L;
	for(int i = 0; i < M; i++) { A[i] = _A[i]; B[i] = _B[i]; C[i] = _C[i]; }
	for(int i = 0; i < Q; i++) { S[i] = _S[i]; T[i] = _T[i]; }
	for(int i = 0; i < K; i++) U[i] = _U[i];
	for(int i = 0; i < L; i++) X[i] = _X[i];
	for(int i = 0; i < N; i++) fill(rawd[i], rawd[i]+MAXN, INFLL);
	for(int i = 0; i < M; i++) rawd[A[i]][B[i]] = C[i];
	for(int i = 0; i < N; i++) fill(rawidx[i], rawidx[i]+MAXN, -1);
	for(int i = 0; i < M; i++) rawidx[A[i]][B[i]] = i;
	for(int i = 0; i < N; i++) fill(d[i], d[i]+MAXN, INFLL);
	for(int i = 0; i < N; i++) d[i][i] = 0;
	for(int i = 0; i < M; i++) d[A[i]][B[i]] = C[i];
	for(int i = 0; i < K; i++) d[A[U[i]]][B[U[i]]] = INFLL;
	for(int k = 0; k < N; k++) for(int i = 0; i < N; i++) for(int j = 0; j < N; j++)
		upmin(d[i][j], d[i][k] + d[k][j]);
	//for(int i = 0; i < L; i++) printf("%d", X[i]); puts("");
	process(); getAns(); printAns();
	/*for(int i = 0; i < Q; i++) {
		printf("PATH %d\n", i);
		for(int v : AnsPath[i]) printf("%d ", v); puts("");
	}
	for(int i = 0; i <= 5; i++) {
		printf("QUERIES %d\n", i);
		for(int v : VQ[i]) printf("%d ", v); puts("");
	}*/
}

Compilation message

Anna.cpp: In function 'int querycountF(const std::vector<int>&, std::vector<int>&, std::vector<int>&, int, int)':
Anna.cpp:66:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 66 ms 17144 KB Output isn't correct - Wrong Answer [9]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 69 ms 17144 KB Output isn't correct - Wrong Answer [8]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 69 ms 17144 KB Output isn't correct - Wrong Answer [8]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 72 ms 17144 KB Output isn't correct - Wrong Answer [8]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 75 ms 17144 KB Output isn't correct - Wrong Answer [8]
2 Incorrect 69 ms 17144 KB Output isn't correct - Wrong Answer [8]
3 Incorrect 78 ms 17144 KB Output isn't correct - Wrong Answer [6]
4 Incorrect 72 ms 17144 KB Output isn't correct - Wrong Answer [6]
5 Incorrect 78 ms 17144 KB Output isn't correct - Wrong Answer [8]
6 Incorrect 69 ms 17144 KB Output isn't correct - Wrong Answer [9]
7 Incorrect 78 ms 17144 KB Output isn't correct - Wrong Answer [9]
8 Incorrect 75 ms 17144 KB Output isn't correct - Wrong Answer [9]
9 Incorrect 76 ms 17144 KB Output isn't correct - Wrong Answer [9]
10 Incorrect 84 ms 17144 KB Output isn't correct - Wrong Answer [9]
11 Incorrect 84 ms 17144 KB Output isn't correct - Wrong Answer [9]
12 Partially correct 78 ms 17144 KB Output is partially correct - L = 66
13 Correct 212 ms 17144 KB Output is correct - L = 42
14 Incorrect 81 ms 17144 KB Output isn't correct - Wrong Answer [8]
15 Incorrect 81 ms 17144 KB Output isn't correct - Wrong Answer [6]
16 Correct 81 ms 17144 KB Output is correct - L = 44
17 Incorrect 72 ms 17144 KB Output isn't correct - Wrong Answer [9]
18 Incorrect 79 ms 17144 KB Output isn't correct - Wrong Answer [9]
19 Incorrect 69 ms 17144 KB Output isn't correct - Wrong Answer [9]
20 Correct 81 ms 17144 KB Output is correct - L = 62
21 Correct 99 ms 17144 KB Output is correct - L = 40
22 Incorrect 75 ms 17144 KB Output isn't correct - Wrong Answer [9]
23 Incorrect 72 ms 17144 KB Output isn't correct - Wrong Answer [9]
24 Incorrect 75 ms 17144 KB Output isn't correct - Wrong Answer [9]