122072024-12-09 12:37:42CsongiSzámjegycserecpp17Wrong answer 0/100170ms764 KiB
#include <bits/stdc++.h>
using namespace std;

bool ketnulla(const string& str)
{
    int szam = 0;
    for (char c : str)
    {
        if (c=='0')
        {
            szam++;
        }
        if (szam == 2)
        {
            return true;
        }
    }
    return false;
}


int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n; cin >> n;
    for (int i = 0; i < n; i++)
    {
        string be; cin >> be;
        //string be = to_string(be);
        if (be.size() == 1)
        {
            if (be == "0")
            {
                cout << "0" << endl;
            }
            else
            {
                cout << "-1" << endl;
            }
        }
        else if ((be[be.size()-1]=='0' && be[be.size()-2]=='0') || (be[be.size()-1]=='5' && be[be.size()-2]=='2') || (be[be.size()-1]=='5' && be[be.size()-2]=='7') || (be[be.size()-1]=='0' && be[be.size()-2]=='5'))
        {
            cout << "0" << endl;
        }
        else if (be[be.size()-1]=='0')
        {
            string str = be; str.pop_back();
            if (str.find("0") != string::npos || str.find("5") != string::npos)
            {
                cout << "1" << endl;
            }
            else
            {
                cout << "-1" << endl;
            }
        }
        else if (be[be.size()-2]=='0')
        {
            string str = be; char x = str.back(); str.pop_back(); str.pop_back(); str.push_back(x);
            if (be[be.size()-1]=='5')
            {
                cout << "1" << endl;
            }
            else if (str.find("0") != string::npos)
            {
                cout << "1" << endl;
            }
            else if (str.find("5") != string::npos)
            {
                cout << "2" << endl;
            }
            else
            {
                cout << "-1" << endl;
            }
        }
        else if (be[be.size()-1]=='5')
        {
            string str = be; str.pop_back();
            if (str.find("7") != string::npos || str.find("2") != string::npos || be[be.size()-2]=='0')
            {
                cout << "1" << endl;
            }
            else if (ketnulla(str))
            {
                cout << "2" << endl;
            }
            else
            {
                cout << "-1" << endl;
            }
        }
        else if ((be[be.size()-1]=='2' && be[be.size()-2]=='5') || (be[be.size()-1]=='7' && be[be.size()-2]=='5'))
        {
            cout << "1" << endl;
        }
        else if ((be.find("7") != string::npos && be.find("5") != string::npos) || (be.find("2") != string::npos && be.find("5") != string::npos) || (be.find("5") != string::npos && be.find("0") != string::npos) || ketnulla(be))
        {
            cout << "2" << endl;
        }
        else
        {
            cout << "-1" << endl;
        }
    }
    
    return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted1ms320 KiB
subtask20/21
2Wrong answer46ms472 KiB
subtask30/23
3Wrong answer163ms568 KiB
4Wrong answer163ms568 KiB
5Wrong answer168ms568 KiB
6Wrong answer170ms568 KiB
7Wrong answer162ms564 KiB
8Wrong answer168ms568 KiB
9Wrong answer162ms660 KiB
10Wrong answer166ms448 KiB
11Wrong answer163ms764 KiB
12Wrong answer170ms444 KiB
13Wrong answer163ms436 KiB
14Wrong answer168ms448 KiB
15Wrong answer167ms452 KiB
16Wrong answer163ms452 KiB
17Wrong answer167ms468 KiB
18Wrong answer162ms568 KiB
19Wrong answer168ms564 KiB
20Wrong answer163ms568 KiB
21Wrong answer170ms568 KiB
22Wrong answer163ms692 KiB
23Wrong answer136ms568 KiB
subtask40/41
24Accepted1ms320 KiB
25Accepted1ms376 KiB
26Accepted1ms320 KiB
27Accepted1ms516 KiB
28Accepted1ms320 KiB
29Accepted1ms320 KiB
30Accepted1ms320 KiB
31Accepted1ms320 KiB
32Accepted1ms320 KiB
33Wrong answer1ms320 KiB
34Accepted1ms320 KiB
35Accepted1ms552 KiB
36Accepted2ms320 KiB
37Accepted14ms432 KiB
38Accepted1ms320 KiB
39Accepted1ms340 KiB
40Accepted1ms536 KiB
41Accepted1ms332 KiB
42Accepted2ms508 KiB
43Accepted2ms320 KiB
44Accepted3ms320 KiB
45Accepted2ms320 KiB
46Wrong answer1ms320 KiB
47Wrong answer2ms320 KiB
subtask50/15
48Wrong answer4ms320 KiB
49Wrong answer3ms568 KiB
50Wrong answer153ms440 KiB
51Wrong answer2ms468 KiB
52Wrong answer37ms320 KiB
53Accepted3ms320 KiB
54Accepted4ms444 KiB
55Accepted20ms508 KiB
56Accepted151ms704 KiB
57Accepted3ms588 KiB
58Accepted3ms588 KiB
59Accepted3ms588 KiB
60Accepted4ms464 KiB
61Accepted4ms436 KiB
62Accepted4ms452 KiB
63Accepted4ms320 KiB
64Accepted170ms716 KiB
65Accepted167ms568 KiB
66Accepted157ms604 KiB