Submission details
Task:Hypyt
Sender:Interaalimato
Submission time:2025-11-06 19:13:32 +0200
Language:C++ (C++11)
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
#40
#50
Test results
testverdicttimegroup
#1ACCEPTED0.00 s1, 2, 3, 4, 5details
#20.00 s1, 2, 3, 4, 5details
#30.00 s1, 2, 3, 4, 5details
#4ACCEPTED0.00 s1, 2, 3, 4, 5details
#5ACCEPTED0.00 s1, 2, 3, 4, 5details
#60.01 s2, 5details
#70.01 s2, 5details
#80.01 s2, 5details
#90.12 s3, 4, 5details
#100.13 s3, 4, 5details
#110.14 s3, 4, 5details
#120.15 s4, 5details
#130.17 s4, 5details
#140.16 s4, 5details
#150.28 s5details
#160.36 s5details
#170.29 s5details
#180.41 s5details
#190.12 s5details
#200.13 s5details
#210.10 s5details
#22ACCEPTED0.00 s1, 2, 3, 4, 5details
#23ACCEPTED0.00 s1, 2, 3, 4, 5details
#24ACCEPTED0.08 s5details
#25ACCEPTED0.08 s5details
#260.18 s5details
#27ACCEPTED0.08 s5details

Code

#include <bits/stdc++.h>

using namespace std;

// read from file instead of console:
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
typedef bitset<250> ibs;

const int M = 1000000007;
typedef long long ll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef pair<int, int> pi;
typedef queue<int> qi;
typedef stack<int> si;
typedef priority_queue<int> pqi;
typedef deque<int> dqi;
typedef unordered_set<int> seti;
typedef unordered_map<int,int> mapi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
typedef vector<vector<vector<long long>>> vvvll;
typedef pair<long long, long long> pll;
typedef queue<long long> qll;
typedef stack<long long> sll;
typedef priority_queue<long long> pqll;
typedef deque<long long> dqll;
typedef unordered_set<long long> setll;
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rloop(i, a, b) for (int i = a; i > b; i--)
#define each(a, c) for (auto a : c)
#define all(x) x.begin(), x.end()
#define PI M_PI
#define PB push_back
#define P push
#define POB pop_back
#define F first
#define S second
#define sz size()
#define R1(a) int a; cin >> a
#define R2(a, b) int a,b; cin >> a >> b
#define R3(a, b, c) int a,b,c; cin >> a >> b >> c
#define R4(a, b, c, d) int a,b,c,d; cin >> a >> b >> c >> d
#define WS(a) cout << a << " "
#define WN(a) cout << a << "\n"
#define WNL cout << "\n"

// graph of rows
vi g[251];

string mat[251];
int m,n,q;
ibs rows[251];

void construct_graph(){
  loop(i,0,m){
    ibs bs;
    loop(j,0,n){
      if(mat[i][j] == '.') bs.set(j);
    }
    rows[i] = bs;
  }
  loop(i,0,m){
    loop(j,i+1,m){
      auto common = rows[i] & rows[j];
      if (!common.none()) {
        g[i].PB(j);
        g[j].PB(i);
      }
    }
  }
}

// x = col, y = row
int query(int x1, int y1, int x2, int y2){
  if(x1 == x2 && y1 == y2) return 0;
  if(x1 == x2 || y1 == y2) return 1;
  qi bfs;
  qi temp;
  int d[251];
  d[y1] = 6767;
  each(ri, g[y1]){
    if(rows[ri][x1]) { d[ri] = 1; bfs.push(ri); }
    else {d[ri] = 2; temp.push(ri);}
    if(ri == y2) {

      if(!rows[y1][x2]) d[ri]++;
      return d[ri];
    }
  }
  while(!temp.empty()){
    bfs.push(temp.front());
    temp.pop();
  }
  int resd = 67676;
  while(!bfs.empty()){
    int top = bfs.front();
    bfs.pop();
    if(resd <= d[top] + 1) return resd;
    each(ri, g[top]){
      if(d[ri] && ri != y2) continue;
      d[ri] = d[top] + 2;
      if(ri == y2) {
        int tresd = d[ri];
        if(!rows[top][x2]) tresd++;
        resd = min(resd, tresd);
      }
      bfs.push(ri);

    }
  }
  return -1;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> m >> n >> q;
    loop(i,0,m){
      cin >> mat[i];
    }
    construct_graph();
    loop(i,0,q){
      R4(y1,x1,y2,x2);
      cout << query(x1-1,y1-1,x2-1,y2-1) << "\n";
    }
    return 0;
}

Test details

Test 1 (public)

Group: 1, 2, 3, 4, 5

Verdict: ACCEPTED

input
4 6 5
.*.***
*...**
*****.
*..*.*
...

correct output
1
0
3
3
-1

user output
1
0
3
3
-1

Test 2

Group: 1, 2, 3, 4, 5

Verdict:

input
10 10 10
..........
.....*....
........*.
*.*....*..
...

correct output
1
2
1
2
2
...

user output
1
1
1
2
2
...

Feedback: Incorrect character on line 2 col 1: expected "2", got "1"

Test 3

Group: 1, 2, 3, 4, 5

Verdict:

input
10 10 10
*...***.**
*****.*...
**..**.**.
..**.**.*.
...

correct output
1
2
2
1
2
...

user output
1
2
2
1
1
...

Feedback: Incorrect character on line 5 col 1: expected "2", got "1"

Test 4

Group: 1, 2, 3, 4, 5

Verdict: ACCEPTED

input
10 10 10
***.*.****
**********
*.********
.*.***.**.
...

correct output
3
4
2
3
4
...

user output
3
4
2
3
4
...

Test 5

Group: 1, 2, 3, 4, 5

Verdict: ACCEPTED

input
10 10 1
.****.****
**.**..***
**********
*******..*
...

correct output
7

user output
7

Test 6

Group: 2, 5

Verdict:

input
250 250 250
.*...*.....*******..**...*.......

correct output
2
3
3
2
2
...

user output
1
3
3
2
2
...

Feedback: Incorrect character on line 1 col 1: expected "2", got "1"

Test 7

Group: 2, 5

Verdict:

input
250 250 250
...*......**.**.*.*..**..*..**...

correct output
2
2
2
2
3
...

user output
2
2
1
2
3
...

Feedback: Incorrect character on line 3 col 1: expected "2", got "1"

Test 8

Group: 2, 5

Verdict:

input
250 250 250
**..**..****.****.*.***.***..*...

correct output
2
3
3
3
3
...

user output
2
3
3
3
3
...

Feedback: Incorrect character on line 30 col 1: expected "2", got "1"

Test 9

Group: 3, 4, 5

Verdict:

input
40 40 200000
...*.**.*..*.............*.*.....

correct output
2
2
2
2
2
...

user output
2
2
1
2
1
...

Feedback: Incorrect character on line 3 col 1: expected "2", got "1"

Test 10

Group: 3, 4, 5

Verdict:

input
40 40 200000
**.**..*.*.*.******....****.*....

correct output
2
1
3
2
2
...

user output
1
1
3
1
2
...

Feedback: Incorrect character on line 1 col 1: expected "2", got "1"

Test 11

Group: 3, 4, 5

Verdict:

input
40 40 200000
.*.*.**.*****.***.*.****.**.**...

correct output
3
3
3
3
3
...

user output
3
3
3
3
3
...

Feedback: Incorrect character on line 85 col 1: expected "2", got "1"

Test 12

Group: 4, 5

Verdict:

input
80 80 200000
*....**.***..****...*.....*......

correct output
2
2
2
2
2
...

user output
2
2
1
1
1
...

Feedback: Incorrect character on line 3 col 1: expected "2", got "1"

Test 13

Group: 4, 5

Verdict:

input
80 80 200000
.***.*..*.***..*****....**...*...

correct output
3
2
2
3
2
...

user output
3
2
2
3
2
...

Feedback: Incorrect character on line 8 col 1: expected "2", got "1"

Test 14

Group: 4, 5

Verdict:

input
80 80 200000
*******.*****.*..*..****...***...

correct output
2
3
1
2
2
...

user output
2
3
1
2
2
...

Feedback: Incorrect character on line 10 col 1: expected "2", got "1"

Test 15

Group: 5

Verdict:

input
250 250 200000
*....*..*..*..**..*.........**...

correct output
3
2
2
2
2
...

user output
3
2
1
2
2
...

Feedback: Incorrect character on line 3 col 1: expected "2", got "1"

Test 16

Group: 5

Verdict:

input
250 250 200000
..*....*..*......*.**.*.*..***...

correct output
2
2
2
2
2
...

user output
2
1
1
2
2
...

Feedback: Incorrect character on line 2 col 1: expected "2", got "1"

Test 17

Group: 5

Verdict:

input
250 250 200000
*..*.*****.*********.****.****...

correct output
3
3
2
2
2
...

user output
3
3
1
2
2
...

Feedback: Incorrect character on line 3 col 1: expected "2", got "1"

Test 18

Group: 5

Verdict:

input
250 250 200000
*********.**********.******.**...

correct output
3
3
3
3
3
...

user output
3
3
3
3
3
...

Feedback: Incorrect character on line 35 col 1: expected "2", got "1"

Test 19

Group: 5

Verdict:

input
250 250 200000
.*****************************...

correct output
104
422
145
93
65
...

user output
-1
-1
-1
-1
-1
...

Feedback: Incorrect character on line 1 col 1: expected "104", got "-1"

Test 20

Group: 5

Verdict:

input
250 250 200000
..****************************...

correct output
57
155
38
65
98
...

user output
-1
-1
-1
-1
-1
...

Feedback: Incorrect character on line 1 col 1: expected "57", got "-1"

Test 21

Group: 5

Verdict:

input
250 250 200000
.*****************************...

correct output
498
498
498
498
498
...

user output
-1
-1
-1
-1
-1
...

Feedback: Incorrect character on line 1 col 1: expected "498", got "-1"

Test 22

Group: 1, 2, 3, 4, 5

Verdict: ACCEPTED

input
10 1 10
*
*
.
*
...

correct output
0
1
1
0
0
...

user output
0
1
1
0
0
...

Test 23

Group: 1, 2, 3, 4, 5

Verdict: ACCEPTED

input
1 10 10
........*.
1 7 1 10
1 4 1 7
1 5 1 1
...

correct output
1
1
1
1
1
...

user output
1
1
1
1
1
...

Test 24

Group: 5

Verdict: ACCEPTED

input
250 1 200000
*
.
*
.
...

correct output
1
1
1
1
1
...

user output
1
1
1
1
1
...

Test 25

Group: 5

Verdict: ACCEPTED

input
1 250 200000
*.*.*...*.*.**.***..**.*.*..**...

correct output
1
1
1
1
1
...

user output
1
1
1
1
1
...

Test 26

Group: 5

Verdict:

input
250 250 200000
.................................

correct output
2
2
2
2
2
...

user output
1
1
1
1
1
...

Feedback: Incorrect character on line 1 col 1: expected "2", got "1"

Test 27

Group: 5

Verdict: ACCEPTED

input
250 250 200000
******************************...

correct output
0
0
0
0
0
...

user output
0
0
0
0
0
...