이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "Azer.h"
#include <vector>
#include <queue>
#include <cstdlib>
#include <cstdio>
#define X first
#define Y second
#define PB push_back
using namespace std;
typedef vector < int > vi;
typedef pair < int, int > pii;
namespace {
const int N = 2005;
int n;
vector < pii > v[N];
queue < bool > info;
int dis[N], mks;
int sto = 0, kolko = 0, jos = 0, ret = 0, brj2, cnt = 0, tko = 0;
pii tmp; int cv, brj;
pii nadi_najblizeg(){
int bst = 0, dod = 501; mks = 0;
for(int i = 0;i < n;i++)
if(dis[i] > mks) mks = dis[i];
for(int i = 0;i < n;i++){
if(dis[i] == -1) continue;
for(pii nxt : v[i]){
if(dis[nxt.X] != -1) continue;
if(nxt.Y + dis[i] - mks < dod){
dod = nxt.Y + dis[i] - mks;
bst = nxt.X;
}
}
}
tko = !((cnt * (mks + n)) & 8);
return {bst, dod};
}
void posalji_broj(int x, int ln){
//printf("A: saljem %d u %d\n", x, ln);
for(int i = ln - 1;i >= 0;i--)
SendA(!!(x & (1 << i)));
}
void korak(){
tmp = nadi_najblizeg();
//printf("A: radim korak tko = %d\n", tko);
cv = tmp.X, brj = tmp.Y;
//printf("A : cv = %d brj = %d\n", cv, brj);
if(tko){
sto = 1; jos = 1; ret = 0;
posalji_broj(brj, 9);
}
else{
sto = 4; jos = 9; ret = 0;
}
}
}
void InitA(int n, int a, vi U, vi V, vi C) {
::n = n;
for(int i = 0;i < a;i++){
v[U[i]].PB({V[i], C[i]});
v[V[i]].PB({U[i], C[i]});
}
for(int i = 0; i < n;i++)
dis[i] = -1;
dis[0] = 0; cnt++;
SendA(0);
Answer();
}
void ReceiveA(bool x) {
if(sto == 0) {
korak(); return;
}
ret = 2 * ret + x; jos--;
//printf("A: jos = %d ret = %d sto = %d\n", jos, ret, sto);
if(jos != 0) return;
if(sto == 1){
if(ret){
jos = 9;
sto = 2;
ret = 0;
}
else{
posalji_broj(cv, 11);
dis[cv] = mks + brj;
if((++cnt) != n)
korak();
}
}
else if(sto == 2){
brj = ret; ret = 0;
jos = 11;
sto = 3;
}
else if(sto == 3){
cv = ret; ret = 0;
dis[cv] = mks + brj;
if((++cnt) != n)
korak();
}
else if(sto == 4){
brj2 = ret; ret = 0;
if(brj2 <= brj){
posalji_broj(0, 1);
brj = brj2;
sto = 5; jos = 11;
}
else{
posalji_broj(1, 1);
posalji_broj(brj, 9);
posalji_broj(cv, 11);
dis[cv] = mks + brj;
if((++cnt) != n)
korak();
}
}
else if(sto == 5){
cv = ret; ret = 0;
dis[cv] = mks + brj;
if((++cnt) != n)
korak();
}
}
vi Answer() {
vi ans(n);
for (int k = 0; k < n; ++k) {
ans[k] = dis[k];
}
return ans;
}
#include "Baijan.h"
#include <vector>
#include <queue>
#include <cstdlib>
#include <cstdio>
#define X first
#define Y second
#define PB push_back
using namespace std;
typedef vector < int > vi;
typedef pair < int, int > pii;
namespace {
const int N = 2005;
int n;
vector < pii > v[N];
queue < bool > info;
int dis[N], mks;
int sto = 0, kolko = 0, jos = 0, ret = 0, brj2, cnt = 0, tko = 0;
pii tmp; int cv, brj;
pii nadi_najblizeg(){
int bst = 0, dod = 501; mks = 0;
for(int i = 0;i < n;i++)
if(dis[i] > mks) mks = dis[i];
for(int i = 0;i < n;i++){
if(dis[i] == -1) continue;
for(pii nxt : v[i]){
if(dis[nxt.X] != -1) continue;
if(nxt.Y + dis[i] - mks < dod){
dod = nxt.Y + dis[i] - mks;
bst = nxt.X;
}
}
}
tko = !!((cnt * (mks + n)) & 8);
return {bst, dod};
}
void posalji_broj(int x, int ln){
//printf("B: saljem %d u %d\n", x, ln);
for(int i = ln - 1;i >= 0;i--)
SendB(!!(x & (1 << i)));
}
void korak(){
tmp = nadi_najblizeg();
//printf("B: radim korak tko = %d\n", tko);
cv = tmp.X, brj = tmp.Y;
//printf("B : cv = %d brj = %d\n", cv, brj);
if(tko){
sto = 1; jos = 1; ret = 0;
posalji_broj(brj, 9);
}
else{
sto = 4; jos = 9; ret = 0;
}
}
}
void InitB(int n, int a, vi U, vi V, vi C) {
::n = n;
for(int i = 0;i < a;i++){
v[U[i]].PB({V[i], C[i]});
v[V[i]].PB({U[i], C[i]});
}
for(int i = 0; i < n;i++)
dis[i] = -1;
dis[0] = 0; cnt++;
SendB(0);
}
void ReceiveB(bool x) {
if(sto == 0) {
korak(); return;
}
ret = 2 * ret + x; jos--;
//printf("B: jos = %d ret = %d sto = %d\n", jos, ret, sto);
if(jos != 0) return;
if(sto == 1){
if(ret){
//printf("tu sam\n");
jos = 9;
sto = 2;
ret = 0;
}
else{
posalji_broj(cv, 11);
dis[cv] = mks + brj;
if((++cnt) != n)
korak();
}
}
else if(sto == 2){
brj = ret; ret = 0;
jos = 11;
sto = 3;
}
else if(sto == 3){
cv = ret; ret = 0;
dis[cv] = mks + brj;
if((++cnt) != n)
korak();
}
else if(sto == 4){
brj2 = ret; ret = 0;
if(brj2 <= brj){
brj = brj2;
sto = 5; jos = 11; ret = 0;
posalji_broj(0, 1);
}
else{
posalji_broj(1, 1);
posalji_broj(brj, 9);
posalji_broj(cv, 11);
dis[cv] = mks + brj;
if((++cnt) != n)
korak();
}
}
else if(sto == 5){
cv = ret; ret = 0;
dis[cv] = mks + brj;
if((++cnt) != n)
korak();
}
}
컴파일 시 표준 에러 (stderr) 메시지
Azer.cpp:24:14: warning: '{anonymous}::kolko' defined but not used [-Wunused-variable]
24 | int sto = 0, kolko = 0, jos = 0, ret = 0, brj2, cnt = 0, tko = 0;
| ^~~~~
Baijan.cpp:24:14: warning: '{anonymous}::kolko' defined but not used [-Wunused-variable]
24 | int sto = 0, kolko = 0, jos = 0, ret = 0, brj2, cnt = 0, tko = 0;
| ^~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |