# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
25614 |
2017-06-23T08:19:42 Z |
윤교준(#1076) |
한자 끝말잇기 (JOI14_kanji) |
C++11 |
|
216 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 INFLL (3700000000000000099ll)
#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[MAXQ+1];
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];
ll ret = d[S][A[U[QN]]] + C[U[QN]] + d[B[U[QN]]][E];
return INFLL <= ret ? INFLL : ret;
}
static void querycountF(const vector<int>& VQ, vector<int>& VQA, vector<int>& VQB, int QA, int QB) {
clv(VQA); clv(VQB); for(int v : VQ) {
const ll la = getDist(S[v], T[v], QA);
const ll lb = getDist(S[v], T[v], QB);
if(la == INFLL) {
VQB.pb(v);
}
else if(la < lb) {
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])]);
clv(VQ[j]); 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 INFLL (3700000000000000099ll)
#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[MAXQ+1];
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 ll bojeong(const ll n) { return INFLL <= n ? INFLL : n; }
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) : 0;
//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) {
bool flag1 = false, flag2 = false;
if(d[S[v]][A[U[QA]]] == INFLL || d[B[U[QA]]][T[v]] == INFLL) flag1 = true;
if(d[S[v]][T[v]] == INFLL) flag2 = true;
if(flag1) { V.pb({INFLL, v}); }
else V.pb({bojeong(d[S[v]][A[U[QA]]] + C[U[QA]] - 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) {
bool flag = false;
if(d[S[v]][A[U[QA]]] == INFLL || d[B[U[QA]]][T[v]] == INFLL) flag = true;
if(flag) { V.pb({INFLL, v}); }
else V.pb({bojeong(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);
clv(VQ[j]); 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
Bruno.cpp: In function 'void splitqueryF(const std::vector<int>&, std::vector<int>&, std::vector<int>&, int, int, int)':
Bruno.cpp:68:24: warning: variable 'flag2' set but not used [-Wunused-but-set-variable]
bool flag1 = false, flag2 = false;
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
72 ms |
17144 KB |
Output isn't correct - Wrong Answer [9] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
69 ms |
17144 KB |
Output isn't correct - Wrong Answer [6] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
68 ms |
17144 KB |
Output isn't correct - Wrong Answer [6] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
69 ms |
17144 KB |
Output isn't correct - Wrong Answer [6] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
72 ms |
17144 KB |
Output isn't correct - Wrong Answer [6] |
2 |
Incorrect |
69 ms |
17144 KB |
Output isn't correct - Wrong Answer [6] |
3 |
Incorrect |
62 ms |
17144 KB |
Output isn't correct - Wrong Answer [6] |
4 |
Incorrect |
75 ms |
17144 KB |
Output isn't correct - Wrong Answer [6] |
5 |
Incorrect |
75 ms |
17144 KB |
Output isn't correct - Wrong Answer [9] |
6 |
Incorrect |
84 ms |
17144 KB |
Output isn't correct - Wrong Answer [9] |
7 |
Incorrect |
69 ms |
17144 KB |
Output isn't correct - Wrong Answer [9] |
8 |
Incorrect |
72 ms |
17144 KB |
Output isn't correct - Wrong Answer [9] |
9 |
Incorrect |
69 ms |
17144 KB |
Output isn't correct - Wrong Answer [9] |
10 |
Incorrect |
72 ms |
17144 KB |
Output isn't correct - Wrong Answer [9] |
11 |
Incorrect |
69 ms |
17144 KB |
Output isn't correct - Wrong Answer [9] |
12 |
Correct |
75 ms |
17144 KB |
Output is correct - L = 40 |
13 |
Correct |
216 ms |
17144 KB |
Output is correct - L = 42 |
14 |
Incorrect |
69 ms |
17144 KB |
Output isn't correct - Wrong Answer [6] |
15 |
Incorrect |
89 ms |
17144 KB |
Output isn't correct - Wrong Answer [6] |
16 |
Correct |
84 ms |
17144 KB |
Output is correct - L = 44 |
17 |
Incorrect |
81 ms |
17144 KB |
Output isn't correct - Wrong Answer [9] |
18 |
Incorrect |
84 ms |
17144 KB |
Output isn't correct - Wrong Answer [9] |
19 |
Incorrect |
78 ms |
17144 KB |
Output isn't correct - Wrong Answer [9] |
20 |
Correct |
86 ms |
17144 KB |
Output is correct - L = 62 |
21 |
Correct |
84 ms |
17144 KB |
Output is correct - L = 40 |
22 |
Incorrect |
72 ms |
17144 KB |
Output isn't correct - Wrong Answer [9] |
23 |
Incorrect |
92 ms |
17144 KB |
Output isn't correct - Wrong Answer [9] |
24 |
Incorrect |
75 ms |
17144 KB |
Output isn't correct - Wrong Answer [9] |