QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#577441 | #9319. Bull Farm | fanhuaxingyu | TL | 49ms | 3840kb | C++20 | 3.1kb | 2024-09-20 11:29:22 | 2024-09-20 11:29:25 |
Judging History
answer
#include <bits/stdc++.h>
#include<array>
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
//#define int long long
#define lowbit(x) ((x) & (-x))
#define ar(x) array<int, x>
#define endl '\n'
#define all(x) begin(x),end(x)
#define all2(x) begin(x)+1,end(x)
using namespace std;
using i64 = long long;
const int N = 2e3 + 10;
const int M = 5e5 + 1;
const int INF = 0x3f3f3f3f;
const ll INF2 = 0x3f3f3f3f3f3f3f3f;
const long double PI = 3.1415926535897932384626;
const long double eps = 1e-5;
const ll mod = 19260817;
const ll mod2 = 998244353;
const int base = 131;
const int base2 = 13331;
int dx[] = { 1,-1,0,0 }, dy[] = { 0,0,1,-1 };
int dx2[] = { 2,-2,0,0 }, dy2[] = { 0,0,2,-2 };
ll qpow(ll a, ll b, ll p)
{
ll ans = 1;
while (b)
{
if (b & 1)
ans *= a, ans %= p;
a *= a;
a %= p;
b >>= 1;
}
return ans % p;
}
ll gcd(ll a, ll b)
{
return !b ? a : gcd(b, a % b);
}
ll lcm(ll a, ll b)
{
return a / gcd(a, b) * b;
}
int n;
void solve()
{
int l, q;
cin >> n >> l >> q;
vector<vector<int>>dis(n + 1, vector<int>(n + 1, INF));
for (int i = 1; i <= n; ++i)
dis[i][i] = 0;
for (int i = 1; i <= l; ++i)
{
string s;
cin >> s;
vector<int>cn(n + 1);
vector<int>t(n + 1);
for (int j = 1; j <= n; ++j)
{
t[j] = (s[2 * j - 2] - 48) * 50 + (s[2 * j - 1] - 48);
cn[t[j]]++;
}
int ok = 0;
for (int j = 1; j <= n; ++j)
{
if (cn[j] == 1)
{
ok++;
}
}
if (ok == n)
{
for (int j = 1; j <= n; ++j)
{
dis[j][t[j]] = min(dis[j][t[j]], i);
}
}
else if (ok == n - 2)
{
vector<int>tmp;
int tmp2 = 0;
for (int j = 1; j <= n; ++j)
if (cn[t[j]] == 2)
tmp.push_back(j);
for (int j = 1; j <= n; ++j)
if (cn[j] == 0)tmp2 = j;
dis[tmp[0]][tmp2] = min(dis[tmp[0]][tmp2], i);
dis[tmp[1]][tmp2] = min(dis[tmp[1]][tmp2], i);
}
}
for (int k = 1; k <= n; ++k)
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= n; ++j)
dis[i][j] = min(dis[i][j], max(dis[i][k], dis[k][j]));
vector<int>ans;
while (q--)
{
string s;
cin >> s;
int a, b, c;
a = (s[0] - 48) * 50 + (s[1] - 48);
b = (s[2] - 48) * 50 + (s[3] - 48);
c = (s[4] - 48) * 50 + (s[5] - 48);
//cin >> a >> b >> c;
if (dis[a][b] <= c)
ans.push_back(1);
else
ans.push_back(0);
}
for (int i = 0; i < ans.size(); ++i)
cout << ans[i];
cout << endl;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
cin >> t;
while (t--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3544kb
input:
2 5 2 4 0305040201 0404040404 030300 020500 050102 020501 6 2 4 030603010601 010203060504 030202 060402 050602 060401
output:
1011 0100
result:
ok 2 lines
Test #2:
score: 0
Accepted
time: 0ms
memory: 3612kb
input:
1 3 3 6 020202 030301 030201 020102 030203 010201 010303 020303 010202
output:
010101
result:
ok single line: '010101'
Test #3:
score: 0
Accepted
time: 49ms
memory: 3840kb
input:
200 10 10 5000 01060:04020305080709 0103070:060204050908 09070503080401060:02 050308010204090:0607 03010502040607080:09 03080109020504060:07 06050:09040302080107 07080305010409060:02 030809010:0204060507 0:060908070201050304 060700 090:03 09080: 070405 010703 0:0100 080601 030600 070206 0:0:09 08040...
output:
011110001101101111111111111111111101111111110111011110110110111011010111111111111111111101111111111110111111110111111111111101111111111110111111111111111111110001100111111111111111111111111011101111111111111111111111111111111111111111011011110100111110111111110111111100111111101110111111111101111110...
result:
ok 200 lines
Test #4:
score: -100
Time Limit Exceeded
input:
1 2000 1 1000000 M=:]A@8UAY7W2JJ4KEHIA[HSCQ1ENSC`JXR;F3PJ:_@41P9Z=9HR8P<<:DUXRR9^WOQFL?NZP6S@=J0^WE32=6;\U0?88]Q_RNPUMT6YU<4<S]H?:7OCQYOT4YAV1^764ENWSDBED>M7A:BI>KSIR48JQ9B=N\5T3N4A2aF0@>3TI81<G7;YE>W`NMP<:IT4CI3D0=GZC3I\CLQJQBA9BDIS9SAM55KaVA<Z@D=>:Y?CQHUQ5U3a6UVI8OKX9_FAF^7=5M85;<0;8YPAM<7Z7PP7A=N...