QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#23226#1827. Token GameYaoBIGAC ✓147ms4160kbC++172.7kb2022-03-14 06:16:042022-04-30 02:36:50

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-04-30 02:36:50]
  • 评测
  • 测评结果:AC
  • 用时:147ms
  • 内存:4160kb
  • [2022-03-14 06:16:04]
  • 提交

answer

#include "bits/stdc++.h"
#define rep(i,a,n) for(auto i=a;i<=n;i++)
#define per(i,a,n) for(auto i=n;i>=a;i--)
#define pb push_back
#define mp make_pair
#define FI first
#define SE second
#define all(A) A.begin(),A.end()
#define sz(A) (int)A.size()
template<class T> inline bool chmax(T &a, T b) {if(a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) {if(b<a) {a=b; return 1;} return 0;}
using namespace std;

string to_string(const string& s) {return '"' + s + '"';}
string to_string(const char* s) {return to_string((string) s);}
template<typename A, typename B> string to_string(pair<A, B> p) {return "(" + to_string(p.FI) + ", " + to_string(p.SE) + ")";}
template<typename A> string to_string(A v) 
{
    bool first = 1;
    string res = "{";
    for(const auto &x: v) 
    {
        if (!first) res += ", ";
        first = 0;
        res += to_string(x);
    }
    res += "}";
    return res;
}

void debug_out() {cerr << endl;} 
template<typename Head, typename... Tail> void debug_out(Head H, Tail... T) 
{
    cerr << " " << to_string(H);
    debug_out(T...);
}
#ifndef ONLINE_JUDGE
    #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
    #define debug(...) if(0) puts("No effect.")
#endif

using ll = long long;
//using LL = __int128;
using pii = pair<int,int>;
using vi = vector<int>;
using db = double;
using ldb = long double;

const int maxn = 300;
const int inf = 0x3f3f3f3f;
const int mod = 998244353;

int sg[maxn+5][maxn+5];

int main()
{
    rep(i,1,maxn) rep(j,i+2,maxn)
    {
        vi mark(maxn*2+1);
        rep(k,1,i-1) mark[sg[k][j]] = 1;
        rep(k,1,j-1) if(abs(i-k)>1) mark[sg[min(i,k)][max(i,k)]] = 1;
        rep(x,0,maxn*2) if(mark[x]==0) {sg[i][j] = x; break;}
    }
    int cas; scanf("%d",&cas); while(cas--)
    {
        int x1,y1,x2,y2; scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
        if(abs(x1-x2)+abs(y1-y2)<=1) puts("0");
        else if(abs(x1-x2)<=1 && abs(y1-y2)<=1) puts("2");
        else
        {
            int sgx = abs(x1-x2)<=1 ? -1 : sg[min(x1,x2)][max(x1,x2)];
            int sgy = abs(y1-y2)<=1 ? -1 : sg[min(y1,y2)][max(y1,y2)];
            int ans = 0;
            auto solve = [&](int sgy,int i,int j) {
                if(sgy==-1) ans++;
                else 
                {
                    rep(k,1,i-1) if(abs(j-k)>1 && sg[k][j]==sgy) ans++;
                    rep(k,1,j-1) if(abs(i-k)>1 && sg[min(i,k)][max(i,k)]==sgy) ans++;
                }
            };
            solve(sgy,min(x1,x2),max(x1,x2));
            solve(sgx,min(y1,y2),max(y1,y2));
            printf("%d\n",ans);
        }
    }
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 23ms
memory: 4160kb

input:

5
6 6 6 3
6 6 2 2
1 6 3 1
3 6 1 3
6 3 1 5

output:

3
0
1
1
0

result:

ok 5 number(s): "3 0 1 1 0"

Test #2:

score: 0
Accepted
time: 147ms
memory: 4064kb

input:

100000
215 233 28 258
15 243 61 148
172 28 96 37
15 132 62 27
41 186 255 54
145 192 249 263
274 70 185 197
50 101 202 230
256 11 285 19
149 268 163 107
177 201 216 126
65 17 105 263
143 148 2 230
40 128 259 176
183 192 293 169
281 59 240 229
257 157 126 182
161 51 164 14
149 191 227 102
55 14 267 19...

output:

3
1
1
1
1
2
2
3
1
1
3
1
1
1
1
3
3
1
1
1
1
1
1
2
1
1
1
2
1
1
3
1
3
1
1
2
1
1
1
3
4
1
1
3
1
2
2
1
1
1
3
1
1
1
3
1
1
1
1
2
3
1
3
1
1
3
1
3
3
2
1
2
3
3
1
1
1
2
2
1
2
1
3
1
1
1
1
1
2
1
4
1
1
1
3
3
1
1
1
1
2
1
1
1
1
3
2
3
2
1
1
3
1
1
1
1
2
1
1
2
3
1
3
1
1
1
2
3
3
1
2
3
1
1
1
1
1
2
3
2
2
2
1
1
3
1
1
1
2
2
...

result:

ok 100000 numbers