Submission #912293

# Submission time Handle Problem Language Result Execution time Memory
912293 2024-01-19T09:43:37 Z winter0101 Stray Cat (JOI20_stray) C++14
100 / 100
61 ms 17024 KB
#include<bits/stdc++.h>
using namespace std;
#define all(fl) fl.begin(),fl.end()
#define pb push_back
#define fi first
#define se second
#define for1(i,j,k) for(int i=j;i<=k;i++)
#define for2(i,j,k) for(int i=j;i>=k;i--)
#define for3(i,j,k,l) for(int i=j;i<=k;i+=l)
#define lb lower_bound
#define ub upper_bound
#define sz(a) (int)a.size()
#define pii pair<int,int>
#define pli pair<long long,int>
#define gcd __gcd
#define lcm(x,y) x*y/__gcd(x,y)
const int maxn=2e4+9;
vector<int>a[maxn];
vector<pii>g[maxn];
bool vis[maxn];
int d[maxn];
int b[12]={0,1,0,0,1,1,0,1,0,0,1,1};
vector<int>id;
int msk[maxn];
int xr=0;
void dfs(int u,int par){
int cnt=0;
for (auto v:g[u]){
if (v.fi==par)continue;
cnt++;
}
if (cnt>1||cnt==0){
int nw=0;
for1(i,0,11){
if (xr==b[i]){
nw=i;
break;
}
}
int lst=0;
for1(i,0,sz(id)-1){
msk[id[i]]=b[nw];
lst=msk[id[i]];
nw=(nw+1)%12;
}
id.clear();
xr=(lst^1);
}
int xd=xr;
for (auto v:g[u]){
if (v.fi==par)continue;
id.pb(v.se);
dfs(v.fi,u);
xr=xd;
}
}
std::vector<int> Mark(int N, int M, int A, int B,std::vector<int> U, std::vector<int> V) {
  int n=N,m=M;
  if (B==0){
  std::vector<int> x(M);
  for1(i,0,m-1){
  a[U[i]].pb(V[i]);
  a[V[i]].pb(U[i]);
  }
  vis[0]=1;
  queue<int>t;
  t.push(0);
  while (!t.empty()){
  auto u=t.front();
  t.pop();
  for (auto v:a[u]){
  if (vis[v])continue;
  d[v]=d[u]+1;
  t.push(v);
  vis[v]=1;
  }
  }
  for (int i = 0; i < M; ++i) {
  int u=U[i],v=V[i];
  if (d[u]==d[v]){
  int t1=(d[u]%3),t2=(t1+1)%3;
  if (t1==1||t2==1)x[i]|=(1<<0);
  if (t1==2||t2==2)x[i]|=(1<<1);
  x[i]--;
  continue;
  }
  if (d[u]>d[v])swap(u,v);
  int mask=0;
  if (d[u]%3==2||d[v]%3==2)mask|=(1<<1);
  if (d[u]%3==1||d[v]%3==1)mask|=(1<<0);
  x[i]=mask-1;
  }
  return x;
  }
  else {
  for1(i,0,m-1){
  g[U[i]].pb({V[i],i});
  g[V[i]].pb({U[i],i});
  }
  dfs(0,0);
  vector<int>x(M);
  for1(i,0,m-1)x[i]=msk[i];
  //for1(i,0,m-1)cout<<U[i]<<" "<<V[i]<<" "<<x[i]<<'\n';
  return x;
  }
}
#include<bits/stdc++.h>
using namespace std;
#define all(fl) fl.begin(),fl.end()
#define pb push_back
#define fi first
#define se second
#define for1(i,j,k) for(int i=j;i<=k;i++)
#define for2(i,j,k) for(int i=j;i>=k;i--)
#define for3(i,j,k,l) for(int i=j;i<=k;i+=l)
#define lb lower_bound
#define ub upper_bound
#define sz(a) (int)a.size()
#define pii pair<int,int>
#define pli pair<long long,int>
#define gcd __gcd
#define lcm(x,y) x*y/__gcd(x,y)
namespace {
 
int A, B;
int step = 0;
int nw=0;
}  // namespace
int c[12]={0,1,0,0,1,1,0,1,0,0,1,1};
set<int>patt;
void Init(int A, int B) {
  ::A = A;
  ::B = B;
  if (B==0){
  return;
  }
  for1(i,0,11-5+1){
  int cc=0,sum=0;
  for1(j,i,i+4){
  sum+=c[j]*(1<<cc);
  cc++;
  }
  patt.insert(sum);
  }
}
int cnt[3];
bool detact=false;
int lst=-1;
vector<int>xx,yy;
int Move(std::vector<int> y) {
  //
  if (B==0){
  int ct=0;
  for1(i,0,2){
  if (y[i]!=0)ct++;
  }
  if (ct==1){
  for1(i,0,2){
  if (y[i]!=0)return i;
  }
  }
  for1(i,0,2)cnt[i]=0;
  for1(i,0,2){
  if (y[i]!=0){
  int j=i+1;
  for1(k,0,1){
  if (j>>k&1){
  cnt[(1<<k)]++;
  }
  else {
  cnt[0]++;
  }
  }
  }
  }
  for1(i,0,2){
  if (cnt[i]==2){
  int ans=i;
  int gg=(i-1+3)%3;
  ans+=gg;
  return ans-1;
  }
  }
  }
  //
  nw++;
  /*cout<<"STEP "<<nw<<'\n';
  for1(i,0,A-1)cout<<y[i]<<" ";
  cout<<'\n';*/
  int deg=(nw>1);
  for1(i,0,A-1)deg+=y[i];
  if (nw==1&&deg>=3){
  for1(i,0,A-1){
  if (y[i]==1){
  lst=i;
  detact=1;
  return i;
  }
  }
  }
  if (nw==1&&deg==1){
  step=0;
  detact=1;
  xx.clear();
  for1(i,0,A-1){
  if (y[i]==1){
  lst=i;
  return i;
  }
  }
  }
  //cerr<<deg<<" "<<detact<<'\n';
  if (deg>=3&&!detact){
  if (lst!=-1)y[lst]++;
  detact=1;
  for1(i,0,A-1){
  if (y[i]==1){
  if (i==lst){
  lst=xx.back();
  xx.pop_back();
  step=0;
  return -1;
  }
  xx.clear();
  step=0;
  lst=i;
  return i;
  }
  }
  }
  int gg=0;
  for1(i,0,A-1){
  gg+=y[i];
  }
  if (gg==0){
  detact=1;
  }
  //cerr<<"STEP "<<nw<<" "<<detact<<" "<<sz(xx)<<'\n';
  if (!detact){
  step++;
  for1(i,0,A-1){
  for1(j,1,y[i]){
  yy.pb(i);
  }
  }
  if (nw<4){
  lst=yy.back();
  xx.pb(lst);
  return yy.back();
  }
  if (step==4){
  int mk=0;
  for1(i,0,4){
  mk+=yy[i]*(1<<i);
  }
  if (patt.find(mk)==patt.end()){
  step=0;
  detact=1;
  xx.clear();
  }
  else {
  detact=1;
  }
  }
  }
  //cerr<<"STEP "<<detact<<" "<<sz(xx)<<'\n';
  //cerr<<"check "<<detact<<'\n';
  if (detact) {
  if (step){
  lst=xx.back();
  xx.pop_back();
  step=0;
  return -1;
  }
  else {
  if (!xx.empty()){
  lst=xx.back();
  xx.pop_back();
  return lst;
  }
  if (gg==1){
  for1(i,0,A-1){
  if (y[i]==1){
  lst=i;
  return i;
  }
  }
  }
  if (lst!=-1)y[lst]++;
  for1(i,0,A-1){
  if (y[i]==1){
  lst=i;
  return i;
  }
  }
  }
  }
}

Compilation message

Anthony.cpp: In function 'std::vector<int> Mark(int, int, int, int, std::vector<int>, std::vector<int>)':
Anthony.cpp:58:7: warning: unused variable 'n' [-Wunused-variable]
   58 |   int n=N,m=M;
      |       ^

Catherine.cpp: In function 'int Move(std::vector<int>)':
Catherine.cpp:192:1: warning: control reaches end of non-void function [-Wreturn-type]
  192 | }
      | ^
# Verdict Execution time Memory Grader output
1 Correct 31 ms 16012 KB Output is correct
2 Correct 1 ms 1808 KB Output is correct
3 Correct 26 ms 15476 KB Output is correct
4 Correct 38 ms 17024 KB Output is correct
5 Correct 38 ms 17008 KB Output is correct
6 Correct 30 ms 15736 KB Output is correct
7 Correct 28 ms 15724 KB Output is correct
8 Correct 35 ms 16468 KB Output is correct
9 Correct 36 ms 16448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 16012 KB Output is correct
2 Correct 1 ms 1808 KB Output is correct
3 Correct 26 ms 15476 KB Output is correct
4 Correct 38 ms 17024 KB Output is correct
5 Correct 38 ms 17008 KB Output is correct
6 Correct 30 ms 15736 KB Output is correct
7 Correct 28 ms 15724 KB Output is correct
8 Correct 35 ms 16468 KB Output is correct
9 Correct 36 ms 16448 KB Output is correct
10 Correct 28 ms 13628 KB Output is correct
11 Correct 28 ms 13904 KB Output is correct
12 Correct 26 ms 13940 KB Output is correct
13 Correct 33 ms 13852 KB Output is correct
14 Correct 28 ms 14192 KB Output is correct
15 Correct 31 ms 14452 KB Output is correct
16 Correct 32 ms 16632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 13616 KB Output is correct
2 Correct 2 ms 1808 KB Output is correct
3 Correct 25 ms 13128 KB Output is correct
4 Correct 42 ms 14976 KB Output is correct
5 Correct 35 ms 14956 KB Output is correct
6 Correct 27 ms 13476 KB Output is correct
7 Correct 27 ms 13428 KB Output is correct
8 Correct 33 ms 14244 KB Output is correct
9 Correct 34 ms 14192 KB Output is correct
10 Correct 34 ms 13908 KB Output is correct
11 Correct 30 ms 13828 KB Output is correct
12 Correct 28 ms 13948 KB Output is correct
13 Correct 28 ms 13948 KB Output is correct
14 Correct 41 ms 14108 KB Output is correct
15 Correct 32 ms 14204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 13616 KB Output is correct
2 Correct 2 ms 1808 KB Output is correct
3 Correct 25 ms 13128 KB Output is correct
4 Correct 42 ms 14976 KB Output is correct
5 Correct 35 ms 14956 KB Output is correct
6 Correct 27 ms 13476 KB Output is correct
7 Correct 27 ms 13428 KB Output is correct
8 Correct 33 ms 14244 KB Output is correct
9 Correct 34 ms 14192 KB Output is correct
10 Correct 34 ms 13908 KB Output is correct
11 Correct 30 ms 13828 KB Output is correct
12 Correct 28 ms 13948 KB Output is correct
13 Correct 28 ms 13948 KB Output is correct
14 Correct 41 ms 14108 KB Output is correct
15 Correct 32 ms 14204 KB Output is correct
16 Correct 25 ms 11860 KB Output is correct
17 Correct 25 ms 12036 KB Output is correct
18 Correct 25 ms 11904 KB Output is correct
19 Correct 25 ms 11900 KB Output is correct
20 Correct 30 ms 12660 KB Output is correct
21 Correct 34 ms 12344 KB Output is correct
22 Correct 33 ms 14444 KB Output is correct
23 Correct 27 ms 12148 KB Output is correct
24 Correct 26 ms 12156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2080 KB Output is correct
2 Correct 1 ms 1808 KB Output is correct
3 Correct 2 ms 2080 KB Output is correct
4 Correct 3 ms 2072 KB Output is correct
5 Correct 2 ms 2076 KB Output is correct
6 Correct 2 ms 2064 KB Output is correct
7 Correct 2 ms 2068 KB Output is correct
8 Correct 3 ms 2072 KB Output is correct
9 Correct 2 ms 2080 KB Output is correct
10 Correct 2 ms 2076 KB Output is correct
11 Correct 2 ms 2076 KB Output is correct
12 Correct 2 ms 2076 KB Output is correct
13 Correct 2 ms 2080 KB Output is correct
14 Correct 2 ms 2072 KB Output is correct
15 Correct 2 ms 2064 KB Output is correct
16 Correct 2 ms 2076 KB Output is correct
17 Correct 2 ms 2080 KB Output is correct
18 Correct 2 ms 2080 KB Output is correct
19 Correct 2 ms 2068 KB Output is correct
20 Correct 2 ms 2064 KB Output is correct
21 Correct 2 ms 2080 KB Output is correct
22 Correct 2 ms 2064 KB Output is correct
23 Correct 2 ms 2080 KB Output is correct
24 Correct 2 ms 2076 KB Output is correct
25 Correct 2 ms 2064 KB Output is correct
26 Correct 2 ms 2080 KB Output is correct
27 Correct 2 ms 2084 KB Output is correct
28 Correct 2 ms 2080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 11872 KB Output is correct
2 Correct 28 ms 13168 KB Output is correct
3 Correct 1 ms 1808 KB Output is correct
4 Correct 20 ms 11648 KB Output is correct
5 Correct 37 ms 14840 KB Output is correct
6 Correct 32 ms 14644 KB Output is correct
7 Correct 28 ms 13692 KB Output is correct
8 Correct 30 ms 14148 KB Output is correct
9 Correct 38 ms 15096 KB Output is correct
10 Correct 32 ms 15260 KB Output is correct
11 Correct 35 ms 15192 KB Output is correct
12 Correct 32 ms 15168 KB Output is correct
13 Correct 32 ms 15148 KB Output is correct
14 Correct 32 ms 15112 KB Output is correct
15 Correct 32 ms 15200 KB Output is correct
16 Correct 33 ms 15160 KB Output is correct
17 Correct 30 ms 14928 KB Output is correct
18 Correct 32 ms 14852 KB Output is correct
19 Correct 31 ms 14936 KB Output is correct
20 Correct 32 ms 14916 KB Output is correct
21 Correct 32 ms 14936 KB Output is correct
22 Correct 31 ms 14948 KB Output is correct
23 Correct 25 ms 12368 KB Output is correct
24 Correct 26 ms 12280 KB Output is correct
25 Correct 27 ms 12880 KB Output is correct
26 Correct 27 ms 12880 KB Output is correct
27 Correct 32 ms 13600 KB Output is correct
28 Correct 28 ms 13388 KB Output is correct
29 Correct 31 ms 13700 KB Output is correct
30 Correct 36 ms 13612 KB Output is correct
31 Correct 26 ms 12144 KB Output is correct
32 Correct 25 ms 12444 KB Output is correct
33 Correct 27 ms 12868 KB Output is correct
34 Correct 26 ms 12788 KB Output is correct
35 Correct 32 ms 13400 KB Output is correct
36 Correct 28 ms 13376 KB Output is correct
37 Correct 28 ms 13400 KB Output is correct
38 Correct 28 ms 13396 KB Output is correct
39 Correct 28 ms 13352 KB Output is correct
40 Correct 28 ms 13408 KB Output is correct
41 Correct 33 ms 14156 KB Output is correct
42 Correct 38 ms 14152 KB Output is correct
43 Correct 31 ms 14164 KB Output is correct
44 Correct 30 ms 14204 KB Output is correct
45 Correct 31 ms 14144 KB Output is correct
46 Correct 30 ms 14272 KB Output is correct
47 Correct 30 ms 13332 KB Output is correct
48 Correct 36 ms 13072 KB Output is correct
49 Correct 28 ms 13136 KB Output is correct
50 Correct 33 ms 13308 KB Output is correct
51 Correct 26 ms 12320 KB Output is correct
52 Correct 27 ms 12308 KB Output is correct
53 Correct 27 ms 12352 KB Output is correct
54 Correct 26 ms 12348 KB Output is correct
55 Correct 26 ms 12380 KB Output is correct
56 Correct 28 ms 12440 KB Output is correct
57 Correct 26 ms 12280 KB Output is correct
58 Correct 27 ms 12452 KB Output is correct
59 Correct 28 ms 12368 KB Output is correct
60 Correct 27 ms 12444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 11824 KB Output is correct
2 Correct 27 ms 12840 KB Output is correct
3 Correct 1 ms 1820 KB Output is correct
4 Correct 24 ms 11660 KB Output is correct
5 Correct 34 ms 14616 KB Output is correct
6 Correct 33 ms 14712 KB Output is correct
7 Correct 27 ms 13692 KB Output is correct
8 Correct 30 ms 13684 KB Output is correct
9 Correct 33 ms 14712 KB Output is correct
10 Correct 35 ms 14704 KB Output is correct
11 Correct 33 ms 14640 KB Output is correct
12 Correct 32 ms 14720 KB Output is correct
13 Correct 36 ms 14708 KB Output is correct
14 Correct 42 ms 14640 KB Output is correct
15 Correct 49 ms 14708 KB Output is correct
16 Correct 61 ms 15064 KB Output is correct
17 Correct 39 ms 14840 KB Output is correct
18 Correct 37 ms 14716 KB Output is correct
19 Correct 40 ms 14708 KB Output is correct
20 Correct 35 ms 14860 KB Output is correct
21 Correct 48 ms 14748 KB Output is correct
22 Correct 30 ms 14800 KB Output is correct
23 Correct 25 ms 12064 KB Output is correct
24 Correct 28 ms 12416 KB Output is correct
25 Correct 48 ms 12668 KB Output is correct
26 Correct 42 ms 12872 KB Output is correct
27 Correct 40 ms 13320 KB Output is correct
28 Correct 33 ms 13484 KB Output is correct
29 Correct 39 ms 13772 KB Output is correct
30 Correct 30 ms 13724 KB Output is correct
31 Correct 27 ms 12416 KB Output is correct
32 Correct 27 ms 12372 KB Output is correct
33 Correct 35 ms 12696 KB Output is correct
34 Correct 27 ms 12876 KB Output is correct
35 Correct 34 ms 13412 KB Output is correct
36 Correct 31 ms 13420 KB Output is correct
37 Correct 32 ms 13432 KB Output is correct
38 Correct 28 ms 13400 KB Output is correct
39 Correct 28 ms 13300 KB Output is correct
40 Correct 36 ms 13436 KB Output is correct
41 Correct 32 ms 14184 KB Output is correct
42 Correct 32 ms 14120 KB Output is correct
43 Correct 31 ms 14436 KB Output is correct
44 Correct 31 ms 14180 KB Output is correct
45 Correct 33 ms 14408 KB Output is correct
46 Correct 33 ms 14392 KB Output is correct
47 Correct 32 ms 13420 KB Output is correct
48 Correct 28 ms 13344 KB Output is correct
49 Correct 30 ms 13168 KB Output is correct
50 Correct 27 ms 13948 KB Output is correct
51 Correct 26 ms 12416 KB Output is correct
52 Correct 25 ms 12508 KB Output is correct
53 Correct 27 ms 12404 KB Output is correct
54 Correct 31 ms 12356 KB Output is correct
55 Correct 27 ms 12348 KB Output is correct
56 Correct 25 ms 12356 KB Output is correct
57 Correct 27 ms 12396 KB Output is correct
58 Correct 27 ms 12308 KB Output is correct
59 Correct 30 ms 12324 KB Output is correct
60 Correct 27 ms 12348 KB Output is correct