#ifndef BALBIT
#include "Anna.h"
#endif
#include <vector>
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define f first
#define s second
#define REP(i,n) for (int i = 0; i<n; ++i)
#define REP1(i,n) for (int i = 1; i<=n; ++i)
#define MX(a,b) a = max(a,b)
#define MN(a,b) a = min(a,b)
#define pb push_back
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(), (x).end()
#ifdef BALBIT
#define bug(...) cerr<<"#"<<__LINE__<<": "<<#__VA_ARGS__<<"- ", _do(__VA_ARGS__)
template<typename T> void _do(T && x) {cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T && x, S && ...y) {cerr<<x<<", "; _do(y...);}
#else
#define bug(...)
#endif // BALBIT
namespace {
const int maxn = 505;
int g[maxn][maxn];
int get(int r, int c, int tr, int tc) {
if (max(abs(r - tr) , abs(c - tc) ) <= 1) {
return (tr-r+1) * 3 + (tc - c+1) + 1;
}else{
if (r < tr-1) return 10; // r++
if (r > tr+1) return 11; // r--;
if (c < tc-1) return 12; // c++
if (c > tc+1) return 13; // c--;
}
}
int raw[maxn][maxn];
#ifdef BALBIT
void SetFlag(int a,int b, int c) {
bug(a,b,c);
assert(c>=1);
}
#endif // BALBIT
} // namespace
void Anna(int N, int K, vector<int> R, vector<int> C) {
vector<int> used(15);
int RS=0, LS=0; // R shift and L shift
for (; RS < 3; ++RS) for (; LS < 3; ++LS) {
fill(used.begin(),used.end(),0);
memset(raw, 0, sizeof raw);
memset(g, 0, sizeof g);
bool useone = 0;
for (int r = 0; r < N; r++) {
for (int c = 0; c < N; c++) {
int id = ((r+RS) % 3) * 3 + ((c+LS) % 3);
if (id < K) {
int yo = get(r, c, R[id],C[id]);
raw[r][c] = yo;
if (yo == 1) useone = 1;
used[yo] = 1;
}else{
if (id == K) {
// nope
}else{
raw[r][c] = 14;
used[14] = 1;
}
}
}
}
if (!useone) {
goto done;
}
}
done:;
assert(used[1] == 0);
int unused = 2;
while (used[unused]) ++unused;
for (int r = 0; r < N; r++) {
for (int c = 0; c < N; c++) {
int id = ((r+RS) % 3) * 3 + ((c+LS) % 3);
if (id == K) SetFlag(r,c,unused-1);
else {
SetFlag(r,c,(raw[r][c]>unused?raw[r][c]-1:raw[r][c])-1);
}
}
}
}
#ifdef BALBIT
signed main(){
Anna(7, 7, {2,2,3,3,4,4,5}, {2,3,2,3,2,3,2});
}
#endif
#include "Bruno.h"
#include <vector>
//#define BALBIT
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define f first
#define s second
#define REP(i,n) for (int i = 0; i<n; ++i)
#define REP1(i,n) for (int i = 1; i<=n; ++i)
#define MX(a,b) a = max(a,b)
#define MN(a,b) a = min(a,b)
#define pb push_back
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(), (x).end()
#ifdef BALBIT
#define bug(...) cerr<<"#"<<__LINE__<<": "<<#__VA_ARGS__<<"- ", _do(__VA_ARGS__)
template<typename T> void _do(T && x) {cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T && x, S && ...y) {cerr<<x<<", "; _do(y...);}
#else
#define bug(...)
#endif // BALBIT
namespace {
const int maxn = 505;
}
std::vector<int> Bruno(int K, std::vector<int> value) {
array<array<int, 5>, 5> tmp;
for (int &x:value)++x;
REP(i,5) REP(j,5) {
tmp[i][j] = (i % 3) * 3 + (j % 3);
// bug(i,j,tmp[i][j]);
}
for (int ti = 1; ti <= 3; ++ti) for (int tj = 1; tj <= 3; ++tj) {
// test it
vector<int> re(K);
bool ok = 1;
int it = 0;
for (int di = -1; di <= 1; ++di) for (int dj = -1; dj <= 1; ++dj) {
if (value[it] == 13) {
if (tmp[ti + di][tj + dj] <= K) {
ok = 0; goto nope;
}
}
++it;
}
bug(ti, tj);
assert(ok);
int gone;
int gi, gj;
it = 0;
for (int di = -1; di <= 1; ++di) for (int dj = -1; dj <= 1; ++dj) {
if (value[it] == 13) {
gi = di; gj = dj==-1?1:dj-1;
goto over1;
}
++it;
}
over1:;
it = 0;
for (int di = -1; di <= 1; ++di) for (int dj = -1; dj <= 1; ++dj) {
if (di == gi && dj == gj) {
gone = value[it];
goto over2;
}
++it;
}
over2:;
it = 0;
for (int di = -1; di <= 1; ++di) for (int dj = -1; dj <= 1; ++dj) {
if (value[it] >= gone) value[it] ++;
int hi = value[it];
bug(it, hi);
if (value[it] == 14) {
++it; continue;
}
int who = tmp[ti + di][tj + dj];
if (value[it] >= 10) {
if (value[it] == 10) re[who] = 2;
if (value[it] == 11) re[who] = 3;
if (value[it] == 12) re[who] = 0;
if (value[it] == 13) re[who] = 1;
}else{
int ai = di + ((hi-1)/3-1);
int aj = dj + ((hi-1)%3-1);
if (ai == 0 && aj == 0) {
re[who] = 4;
}else{
bug("from here!");
if (0 < ai) re[who] = 2;
if (0 > ai) re[who] = 3;
if (0 < aj) re[who] = 0;
if (0 > aj) re[who] = 1;
}
}
bug(it, who, re[who]);
++it;
}
return re;
nope:;
}
}
Compilation message
Anna.cpp: In function 'int {anonymous}::get(int, int, int, int)':
Anna.cpp:48:1: warning: control reaches end of non-void function [-Wreturn-type]
48 | }
| ^
Bruno.cpp: In function 'std::vector<int> Bruno(int, std::vector<int>)':
Bruno.cpp:125:5: warning: control reaches end of non-void function [-Wreturn-type]
125 | }
| ^
Bruno.cpp:89:17: warning: 'gone' may be used uninitialized in this function [-Wmaybe-uninitialized]
89 | if (value[it] >= gone) value[it] ++;
| ^~
Bruno.cpp:77:36: warning: 'gj' may be used uninitialized in this function [-Wmaybe-uninitialized]
77 | if (di == gi && dj == gj) {
| ~~~^~~~~
Bruno.cpp:77:24: warning: 'gi' may be used uninitialized in this function [-Wmaybe-uninitialized]
77 | if (di == gi && dj == gj) {
| ~~~^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
3 ms |
4424 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |