Submission details
Task:Hypyt
Sender:R0B0R0BO
Submission time:2025-11-08 17:43:33 +0200
Language:C++ (C++17)
Status:READY
Result:10
Feedback
groupverdictscore
#1ACCEPTED10
#20
#30
#40
#50
Test results
testverdicttimegroup
#1ACCEPTED0.00 s1, 2, 3, 4, 5details
#2ACCEPTED0.00 s1, 2, 3, 4, 5details
#3ACCEPTED0.00 s1, 2, 3, 4, 5details
#4ACCEPTED0.00 s1, 2, 3, 4, 5details
#5ACCEPTED0.00 s1, 2, 3, 4, 5details
#6--2, 5details
#7--2, 5details
#8--2, 5details
#9--3, 4, 5details
#10--3, 4, 5details
#11--3, 4, 5details
#12--4, 5details
#13--4, 5details
#14--4, 5details
#15--5details
#16--5details
#17--5details
#18--5details
#19--5details
#20--5details
#21--5details
#22ACCEPTED0.00 s1, 2, 3, 4, 5details
#23ACCEPTED0.00 s1, 2, 3, 4, 5details
#24--5details
#25--5details
#26--5details
#27ACCEPTED0.19 s5details

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:52:48: warning: comparison of integer expressions of different signedness: 'int' and 'const size_type' {aka 'const long unsigned int'} [-Wsign-compare]
   52 |         while ((res = line.find('.', res + 1)) !=
      |                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
   53 |            string::npos)
      |            ~~~~~~~~~~~~                         
input/code.cpp:44:14: warning: unused variable 'valmis' [-Wunused-variable]
   44 |         bool valmis = false;
      |              ^~~~~~
input/code.cpp:128:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::set<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  128 |         for (int i = 0; i < turvalliset.size(); i++) //tämä on niin paljon kuin on lyhyin matka (tai pisin matka)
      |                         ~~^~~~~~~~~~~~~~~~~~~~
input/code.cpp:141:31: warning: comparison of integer expressions of differen...

Code

#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <algorithm>
#include <optional>
#include <string>
#include <stack>
#include <set>
 
 
typedef long long ll;
typedef unsigned long long ull;
//typedef unsigned int uint;
 
using namespace std;

// indeksi, väri, määrä
unordered_map<int,pair<int,int>> pysty;
// indeksi, väri, määrä
unordered_map<int,pair<int,int>> vaaka;

int haku(){
    return 0;
}
 
int main(){
    int n,m,q = 0;

    cin >> n >> m >> q;

    set<pair<int,int>> turvalliset;


    //Tämä on ilmeisesti liian hidas
    for (int y = 1; y <= n; y++) // O(n) siis n arvo eli sanotaan vaikka 250
    {
        string line;
        cin >> line;


        bool valmis = false;

        if(line[0] == '.'){
            turvalliset.insert(make_pair(1,y));
        }

        int res = 0;

        while ((res = line.find('.', res + 1)) !=
           string::npos)
         turvalliset.insert(make_pair(res+1,y));
        
        


        /* // Liian hidas
        int x = 1;
        for (auto &&i : line) //O(n)
        {
            if(i == 46){
                turvalliset.insert(make_pair(x,y)); //O(log n)
            }
            x++;
        }
       */
    }

    //cout << turvalliset.size();

    //return 0;

    string vastaukset;

    //Kaikki ton for loopin sisällä saisi olla (teoriassa) vain log n
    // kuitenkin testeissä on mahdollista saada huonommallakin (q 250 eli jopa n^3)
    // eli kyseessä pitäisi olla 

    for (int i = 0; i < q; i++) //O(n) - sanotaan 250
    {
        
      //  int matka = 0;
        bool loytyi = false;
        int x1,y1,x2,y2 = 0;
        cin >> y1 >> x1 >> y2 >> x2;

        pair<int,int> alku = make_pair(x1,y1);
        pair<int,int> loppu = make_pair(x2,y2);
        
        //Jos alku ja loppu samat
        if(alku == loppu){
            vastaukset += "0\n";
            continue;
        }
        /*
        //Oletetaan, että ei ala ikinä hirviöstä
        //JOs alkaa hirviöstä
        if(find(turvalliset.begin(),turvalliset.end(), alku) == turvalliset.end()){
            vastaukset += "-1\n";
            continue;
        }
        */
        
        
            
        
        set<pair<int,int>> testaus;
        testaus = turvalliset; //O(niin paljon kun turvallisia on) tämä voi olla ongelmallinen
        testaus.insert(make_pair(0,0));

        deque<pair<int,int>> lapset;
        //Pitää kirjaa lasten syvyyksistä - pitäisi korvata
        deque<int> syvyydet; 

        auto eka = find(testaus.begin(),testaus.end(),alku); //O(log (niin paljon kun turvallisia))
        if(eka != testaus.end()){
            testaus.erase(eka); //O(1), koska tiedossa (?)
        }
        else{
            cout << "VALTAVA VIRHE !!!";
        }

        lapset.push_back(alku);
        syvyydet.push_back(0);
      
        for (int i = 0; i < turvalliset.size(); i++) //tämä on niin paljon kuin on lyhyin matka (tai pisin matka)
        {   
            if(loytyi){
                break;
            }
            else if(lapset.size() == 0){
                vastaukset.append("-1 \n");
                break;
            }


            // Ekaks X samat eli pysty suunnas (käyttää ekaa lasta ain)
            bool xMenossa = true;
            for (int j = 0; j < turvalliset.size(); j++) //Tämä on niin paljon kun niitä lapsia sattuu olemaan (joka voi olla aika paljon)
            //MUTTA
            //On käytännössä enintään O(niin paljon kun turvallista) niin paljon kun 
            {
                if(xMenossa){
                    //X oma
                    int key = lapset[0].first;
                    auto it = find_if(testaus.begin(),testaus.end(),[key](const auto p){return p.first == key;}); //O(log n-lukuja) teoriassa, koska pitäisi poistaa kokoa ajan niitä

                    if(it == testaus.end()){
                        xMenossa = false;
                        continue;
                    }

                    auto pari = make_pair(it->first,it->second);
                    //testaus.erase(it); //O(n-1)  eli liian pitkä...
                    testaus.erase(it); //O(log(n))

                    //sama kun y mutta en jaksa fiksaa
                    if(pari == loppu){
                        loytyi = true;
                        int joku = syvyydet[0] + 1;
                        vastaukset.append(to_string(joku));
                        vastaukset.append("\n");
                        break;
                    }
                    
                    lapset.push_back(pari);

                    syvyydet.push_back(syvyydet[0]+1);




                }
                else{
                    //Y oma
                    int key = lapset[0].second;
                    auto it = find_if(testaus.begin(),testaus.end(),[key](const auto p){return p.second == key;});

                    if(it == testaus.end()){
                        break;
                    }

                    auto pari = make_pair(it->first,it->second);
                    testaus.erase(it);

                    //sama kun y mutta en jaksa fiksaa
                    if(pari == loppu){
                        loytyi = true;
                        int joku = syvyydet[0] + 1;
                        vastaukset.append(to_string(joku));
                        vastaukset.append("\n");
                        break;
                    }
                    
                    lapset.push_back(pari);

                    syvyydet.push_back(syvyydet[0]+1); //log n



                }
            }

            lapset.erase(lapset.begin());
            syvyydet.erase(syvyydet.begin());
            


        }   
        
     
    }

    cout << vastaukset;
 
    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: ACCEPTED

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

correct output
1
2
1
2
2
...

user output
1
2
1
2
2
...

Test 3

Group: 1, 2, 3, 4, 5

Verdict: ACCEPTED

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

correct output
1
2
2
1
2
...

user output
1
2
2
1
2
...

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
(empty)

Test 7

Group: 2, 5

Verdict:

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

correct output
2
2
2
2
3
...

user output
(empty)

Test 8

Group: 2, 5

Verdict:

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

correct output
2
3
3
3
3
...

user output
(empty)

Test 9

Group: 3, 4, 5

Verdict:

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

correct output
2
2
2
2
2
...

user output
(empty)

Test 10

Group: 3, 4, 5

Verdict:

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

correct output
2
1
3
2
2
...

user output
(empty)

Test 11

Group: 3, 4, 5

Verdict:

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

correct output
3
3
3
3
3
...

user output
(empty)

Test 12

Group: 4, 5

Verdict:

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

correct output
2
2
2
2
2
...

user output
(empty)

Test 13

Group: 4, 5

Verdict:

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

correct output
3
2
2
3
2
...

user output
(empty)

Test 14

Group: 4, 5

Verdict:

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

correct output
2
3
1
2
2
...

user output
(empty)

Test 15

Group: 5

Verdict:

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

correct output
3
2
2
2
2
...

user output
(empty)

Test 16

Group: 5

Verdict:

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

correct output
2
2
2
2
2
...

user output
(empty)

Test 17

Group: 5

Verdict:

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

correct output
3
3
2
2
2
...

user output
(empty)

Test 18

Group: 5

Verdict:

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

correct output
3
3
3
3
3
...

user output
(empty)

Test 19

Group: 5

Verdict:

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

correct output
104
422
145
93
65
...

user output
(empty)

Test 20

Group: 5

Verdict:

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

correct output
57
155
38
65
98
...

user output
(empty)

Test 21

Group: 5

Verdict:

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

correct output
498
498
498
498
498
...

user output
(empty)

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:

input
250 1 200000
*
.
*
.
...

correct output
1
1
1
1
1
...

user output
(empty)

Test 25

Group: 5

Verdict:

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

correct output
1
1
1
1
1
...

user output
(empty)

Test 26

Group: 5

Verdict:

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

correct output
2
2
2
2
2
...

user output
(empty)

Test 27

Group: 5

Verdict: ACCEPTED

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

correct output
0
0
0
0
0
...

user output
0
0
0
0
0
...