QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#953335#7061. Poker Gameyuanyq5523AC ✓14ms3712kbC++2020.5kb2025-03-27 18:46:382025-03-27 18:46:39

Judging History

This is the latest submission verdict.

  • [2025-03-27 18:46:39]
  • Judged
  • Verdict: AC
  • Time: 14ms
  • Memory: 3712kb
  • [2025-03-27 18:46:38]
  • Submitted

answer

/*
ANALYSIS:

*/
//#pragma GCC optimize(2);
#include <iostream> 
#include <cstring>
#include <string>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <ctime>
#include <random>
#include <iomanip>
#define endl '\n'
using namespace std;
struct Card
{
    int value;
    int suit;

    Card(int id)  
    {
        if(id == 0)
        {
            value = 0;
            suit = 0;
            return;
        }
        value = id % 13;
        if(id % 13 == 0)
            value = 13;
        
        suit = id / 13;
        if(id % 13 != 0)
            suit++;
        if(value == 1)
        {
            value = 14;
        }
        
    }

    Card(int Value, int Suit)
    {
        this->value = Value;
        this->suit = Suit;
    }

    int literal()
    {
        if(value == 14)
            return 1;
        else
            return value;
    }

    bool operator < (const Card &other) const
    {
        return value < other.value;
    }
};
struct Deck
{
    vector<Card> cards;
    int p;
    Deck()
    {
        p = 0;
    }
    void insert(Card card)
    {
        cards.push_back(card);
    }
    Card handout()
    {
        if(p > cards.size() - 1)
        {
            cout << "ERR" << endl;
            exit(1);
        }
        auto res = cards[p];
        p += 1;
        return res;
    }
};
struct Player
{
    int pot;
    int ingame;
    Card hand[2];
    int privalege;
    Player() : hand{Card(0, 0), Card(0, 0)}
    {
        pot = 100;
    }
    void receive(Card card)
    {
        //cout << hand[0].value << " " << hand[1].value << endl;
        if(hand[0].value == 0)
        {
            hand[0] = card;
        }
        else if(hand[1].value == 0)
        {
            hand[1] = card;
        }
        else
        {
            cout << "ERR" << endl;
            exit(1);
        }
    }
    virtual int strategy(int state, vector<Card> pub, int others){cout << "VERR" << endl; exit(1);}
};

struct Comb
{
    vector<Card> cards;
    int rank;
    Card coreCard;
    bool operator < (const Comb &other) const
    {
        if(rank != other.rank)
            return rank < other.rank;
        return coreCard.value < other.coreCard.value;
    }
    bool operator > (const Comb &other) const
    {
        if(rank != other.rank)
            return rank > other.rank;
        return coreCard.value > other.coreCard.value;
    }
    bool operator == (const Comb &other) const
    {
        return (rank == other.rank) && (coreCard.value == other.coreCard.value);
    }
    bool operator != (const Comb &other) const
    {
        return !(*this == other);
    }

    Comb(Card card1, Card card2, vector<Card> &pub) : coreCard(0, 0)
    {
        cards.clear();
        cards.push_back(card1);
        cards.push_back(card2);
        for(auto &card : pub)
        {
            cards.push_back(card);
        }
        valuate();
    }
    bool One2SorF()
    {
        cerr << "One2SorF" << endl;
        cerr << "cardsValue: ";
        for(auto &card : cards)
        {
            cerr << card.value << ' ';
        }
        cerr << endl;
        cerr << "cardsSuit: ";
        for(auto &card : cards)
        {
            cerr << card.suit << ' ';
        }
        cerr << endl;
        vector<int> suitCount(5, 0);
        for(auto &card : cards)
        {
            suitCount[card.suit]++;
        }
        for(auto &r : suitCount)
        {
            if(r >= 4)
            {
                return true;
            }
        }
        vector<int> valueCount(15, 0);
        for(auto &card : cards)
        {
            if(card.value == 14)
            {
                valueCount[1]++;
            }
            valueCount[card.value]++;
        }
        
        for(int start = 10; start >= 1; start--)
        {
            int gaps = 0;  
            int consecutive = 0;  
            
            for(int i = 0; i < 5; i++)
            {
                // 如果 start+i > 14 会导致数组越界
                if(valueCount[start + i] > 0)
                {
                    consecutive++;
                }
                else
                {
                    gaps++;
                }
            }
        
            if((gaps == 1) && (consecutive == 4))
            {
                coreCard = Card(start + 4, 1);
                return true;
            }
        }
        
        return false;
    }
    void valuate()
    {
        valuateRank();
        valuateCoreCard();
    }
    void valuateRank()
    {
        //check for flush
        vector<int> suitCount(5, 0);
        for(auto &card : cards)
        {
            suitCount[card.suit]++;
        }
        coreCard = Card(0, 0);
        for(int i = 1; i <= 4; i++)
        {
            if(suitCount[i] >= 5)
            {
                rank = 5;
                for(auto &card : cards)
                {
                    if(card.suit == i && card.value > coreCard.value)
                    {
                        coreCard = card;
                    }
                }
                return;
            }
        }
        //check for straight
        vector<int> valueCount(15, 0);
        for(auto &card : cards)
        {
            valueCount[card.value]++;
            if(card.value == 14)
            {
                valueCount[1]++;
            }
        }
        for(int i = 14; i >= 5; i--)
        {
            if(valueCount[i] >= 1)
            {
                int count = 0;
                for(int j = i; j >= 1; j--)
                {
                    if(valueCount[j] >= 1)
                    {
                        count++;
                    }
                    else
                    {
                        break;
                    }
                }
                if(count >= 5)
                {
                    rank = 4;
                    coreCard = Card(i, 1);
                    return;
                }
            }
        }
        //check for three
        for(int i = 2; i <= 14; i++)
        {
            if(valueCount[i] >= 3)
            {
                rank = 3;
                return;
            }
        }
        //check for pair
        for(int i = 2; i <= 14; i++)
        {
            if(valueCount[i] >= 2)
            {
                rank = 2;
                return;
            }
        }
        //check for high card
        rank = 1;
    }
    void valuateCoreCard()
    {
        vector<int> valueCount(15, 0), suitCount(5, 0);
        for(auto &card : cards)
        {
            suitCount[card.suit]++;
        }
        for(auto &card : cards)
        {
            valueCount[card.value]++;
        }
        if(rank == 1)
        {
            coreCard = Card(0, 0);
            for(auto &card : cards)
            {
                if(card.value > coreCard.value)
                {
                    coreCard = card;
                }
            }
        }
        else if(rank == 2)
        {
            for(int i = 14; i >= 2; i--)
            {
                if(valueCount[i] >= 2)
                {
                    coreCard = Card(i);
                    break;
                }
            }
        }
        else if(rank == 3)
        {
            for(int i = 14; i >= 2; i--)
            {
                if(valueCount[i] >= 3)
                {
                    coreCard = Card(i, 1);
                    break;
                }
            }
        }
        else if(rank == 4)
        {
            return;
        }
        else
        {
            return;
        }
    }
};

struct Player1 : public Player
{
    int strategy(int state, vector<Card> pub, int others) override
    {
        Comb comb(hand[0], hand[1], pub);
        if(state == 1)
        {
            if(pot < 15)
            {
                return 0;
            }
            if(hand[0].suit == hand[1].suit)
            {
                return 1;
            }
            else
            {
                return 0;
            }
        }
        else if(state == 2)
        {
            return 1;
        }
        else
        {
            if(comb.rank >= 2)
            {
                return 1;
            }
            else
            {
                return 0;
            }
        }
    }
}player1;

struct Player2 : public Player
{
    int strategy(int state, vector<Card> pub, int others) override
    {
        
        if(state == 1)
        {
            if((pot >= 15) || ((hand[0].value == 14) && (hand[1].value == 14)))
            {
                return 1;
            }
            else
            {
                return 0;
            }
        }
        else if(state == 2)
        {
            Comb comb(hand[0], hand[1], pub);
            // for(auto &r : comb.cards)
            // {
            //     cout << r.value << char('A' - 1 + r.suit) << ' ';
            // }
            // cout << endl;
            // cout << comb.rank << ' ' << comb.coreCard.value << ' ' << comb.One2SorF() << endl;
            if((comb.rank >= 2) || (comb.One2SorF() == true))
            {
                return 1;
            }
            else
            {
                return 0;
            }
        }
        else
        {
            vector<int> suitCount(5, 0);
            for(auto &r : pub)
            {
                suitCount[r.suit]++;
            }
            for(auto &r : suitCount)
            {
                if(r >= 4)
                {
                    return 0;
                }
            }
            return 1;
        }
    }
}player2;


struct Player3 : public Player
{
    int strategy(int state, vector<Card> pub, int others) override
    {
        Comb comb(hand[0], hand[1], pub);
        if(state == 1)
        {
            if((hand[0].value == 14) || (hand[1].value == 14) || (abs(hand[0].literal() - hand[1].literal()) < 3))
            {
                return 1;
            }
            else
            {
                return 0;
            }
        }
        else if(state == 2)
        {
            vector<int> ValueCount(15, 0);
            for(auto &r : pub)
            {
                ValueCount[r.value]++;
            }
            for(int i = 2; i <= 14; i++)
            {
                if((ValueCount[i] >= 2) && (hand[0].value != i) && (hand[1].value != i))
                {
                    return 0;
                }
            }
            return 1;
        }
        else
        {
            return 1;
        }
    }
}player3;


struct Player4 : public Player
{
    int strategy(int state, vector<Card> pub, int others) override
    {
        Comb comb(hand[0], hand[1], pub);
        if(state == 1)
        {
            if((hand[0].value > 11) || (hand[1].value > 11))
            {
                return 1;
            }
            return 0;
        }
        /*
        else if(state == 2)
        {
           int  maxValue = 0;
            for(auto &r : pub)
            {
                if(r.value > maxValue)
                {
                    maxValue = r.value;
                }
            }
            if((hand[0].value >= maxValue) or (hand[1].value >= maxValue))
            {
                return 1;
            }
            return 0;
        }
        */
        else if(state == 2)
        {
            // 检查是否有手牌大于所有公共牌
            bool hasHigherCard = true;
            for(auto &r : pub)
            {
                if((hand[0].value <= r.value) && (hand[1].value <= r.value))
                {
                    hasHigherCard = false;
                }
            }
            
            // 检查是否能与最大的公共牌配对
            int maxPubValue = 0;
            for(auto &r : pub)
            {
                maxPubValue = max(maxPubValue, r.value);
            }
            bool canPairWithMax = (hand[0].value == maxPubValue || hand[1].value == maxPubValue );
            
            return (hasHigherCard || canPairWithMax) ? 1 : 0;
        }
        else
        {
            if(comb.rank >= 3)
            {
                return 1;
            }
            if(comb.rank >= 2 && pub.size() >= 3)  // 防止数组越界
            {
                vector<Card> sortedPub = pub;
                sort(sortedPub.begin(), sortedPub.end());
                int thirdHighestValue = sortedPub[sortedPub.size() - 3].value;
                
                return (comb.coreCard.value > thirdHighestValue);
            }
            return 0;
        }
    }
}player4;


struct Player5 : public Player
{
    int strategy(int state, vector<Card> pub, int others) override
    {
        Comb comb(hand[0], hand[1], pub);
        if(state == 1)
        {
            if(others == 1)
            {
                return 1;
            }
            else
            {
                return 0;
            }
        }
        else if(state == 2)
        {
            return 1;
        }
        else
        {
            return 1;
        }
    }
}player5;


struct Game
{
    vector<Card> pub;
    vector<Player*> players;
    
    Game(vector<Player*> players)
    {
        this->players = players;
    }
    void play(Deck deck)
    {
        cerr << "NewRound" << endl;
        cerr << "deckValue: ";
        for(auto &r : deck.cards)
        {
            cerr << r.value << ' ';
        }
        cerr << endl;
        cerr << "deckSuit: ";
        for(auto &r : deck.cards)
        {
            cerr << r.suit << ' ';
        }
        cerr << endl;
        pub.clear();
        
        int gamepots = 0, others = 0;
        for(int i = 0; i < players.size(); i++)
        {
            players[i]->hand[0] = Card(0, 0);
            players[i]->hand[1] = Card(0, 0);
            players[i]->privalege = 0;
            players[i]->ingame = ((players[i]->pot) > 0) ? 1 : 0;
        }
        
        // 计算正确的lastPlayer值
        int lastPlayer = 0;
        for(int i = 0; i < players.size(); i++) {
            if(players[i]->ingame == 1) {
                lastPlayer++;
            }
        }
        
        for(int i = 0; i < int(players.size()); i++)
        {
            if(players[i]->ingame == 1)
            {
                players[i]->receive(deck.handout());
                players[i]->receive(deck.handout());
            }
        }
        others = 0;
        for(int i = 0; i < players.size(); i++)
        {
            if(players[i]->ingame == 1)
            {
                if(lastPlayer == 1)
                {
                    continue;
                }
                //cout << 's' << players[i]->strategy(1, pub, others) << endl;
                if(players[i]->strategy(1, pub, others) == 1)
                {
                    if((players[i]->pot) < 15)
                    {
                        gamepots += (players[i]->pot);
                        (players[i]->pot) = 0;
                        (players[i]->privalege) = 1;
                    }
                    else
                    {
                        gamepots += 5;
                        (players[i]->pot) -= 5;
                    }
                    others += 1;
                }
                else
                {
                    (players[i]->ingame) = 0;
                    lastPlayer -= 1;
                    cerr << "player" << i + 1 << " out in state 1" << endl;
                }
            }
        }
        for(int i = 1; i <= 3; i++)
        {
            pub.push_back(deck.handout());
        }
        cerr << "pub: ";
        for(auto &r : pub)
        {
            cerr << r.value << ' ';
        }
        cerr << endl;
        others = 0;
        for(int i = 0; i < players.size(); i++)
        {
            if(players[i]->ingame == 1)
            {
                if(lastPlayer == 1)
                {
                    continue;
                }
                if(players[i]->privalege == 1)
                {
                    continue;
                }
                else
                {
                    if(players[i]->strategy(2, pub, others) == 1)
                    {
                        gamepots += 5;
                        players[i]->pot -= 5;
                        others += 1;
                    }
                    else
                    {
                        players[i]->ingame = 0;
                        lastPlayer -= 1;
                        cerr << "player" << i + 1 << " out in state 2" << endl;
                    }
                }
            }
        }
        
        for(int i = 4; i <= 5; i++)
        {
            pub.push_back(deck.handout());
        }
        cerr << "pub: ";
        for(auto &r : pub)
        {
            cerr << r.value << ' ';
        }
        cerr << endl;
        others = 0;
        for(int i = 0; i < players.size(); i++)
        {
            if(players[i]->ingame == 1)
            {
                if(lastPlayer == 1)
                {
                    continue;
                }
                if(players[i]->privalege == 1)
                {
                    continue;
                }
                else
                {
                    if(players[i]->strategy(3, pub, others) == 1)
                    {
                        gamepots += 5;
                        players[i]->pot -= 5;
                        others += 1;
                    }
                    else
                    {
                        players[i]->ingame = 0;
                        lastPlayer -= 1;
                        cerr << "player" << i + 1 << " out in state 1" << endl;
                    }
                }
            }
        }
        
        vector<pair<Comb, int>> combs;
        for(int i = 0; i < players.size(); i++)
        {
            if(players[i]->ingame == 1)
            {
                auto acomb = pair<Comb, int>(Comb(players[i]->hand[0], players[i]->hand[1], pub), i);
                combs.push_back(acomb);
            }
        }
        
        // 处理combs为空的情况
        if(combs.empty()) {
            cerr << "No winner in this round" << endl;
            return;
        }
        
        sort(combs.begin(), combs.end(), [](pair<Comb, int> a, pair<Comb, int> b)
        {
            if(a.first != b.first)
                return a.first > b.first;
            return a.second > b.second;
        });
        cerr << "combinations: " << endl;
        for(auto &r : combs)
        {
            cerr << "Player" << (r.second + 1) << ':' << "Rank" << r.first.rank << ' ' << "CoreCardValue" << r.first.coreCard.value << endl;
            cerr << "Cards: ";
            for(auto &card : r.first.cards)
            {
                cerr << card.value << char('A' - 1 + card.suit) << ' ';
            }
            cerr << endl << endl;
        }
        int winner = combs[0].second;
        players[winner]->pot += gamepots;
        cerr << "Winner" << winner + 1  << endl;
    }
    vector<int> result()
    {
        vector<int> res;
        for(int i = 0; i < players.size(); i++)
        {
            res.push_back(players[i]->pot);
        }
        return res;
    }
};

void solution()
{
    int n;
    cin >> n;
    vector<Player*> players;
    players.push_back(&player1);
    players.push_back(&player2);
    players.push_back(&player3);
    players.push_back(&player4);
    players.push_back(&player5);
    Game game(players);
    for(int i = 1; i <= n; i++)
    {
        Deck deck;
        for(int j = 1; j <= 15; j++)
        {
            int id;
            cin >> id;
            deck.insert(Card(id));
        }
        game.play(deck);
        
        //cerr << "---------------------" << endl;
    }
    auto res = game.result();
    for(auto &r : res)
    {
        //if(r == 95) {cout << 65 << endl << 100 << endl << 120 << endl << 115 << endl;return;}
        cout << r << endl;
    }
}

signed main() 
{
    ios::sync_with_stdio(0);
    cin.tie(0); 
    cout.tie(0);
    solution();
    return 0;
}

这程序好像有点Bug,我给组数据试试?

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3712kb

input:

2
1 2 8 10 3 11 15 12 14 27 42 43 45 48 13
14 2 8 10 3 11 5 23 1 27 42 43 13 45 48

output:

90
90
100
115
105

result:

ok 5 lines

Test #2:

score: 0
Accepted
time: 0ms
memory: 3712kb

input:

5
9 5 19 35 30 42 18 8 21 51 16 26 32 29 49
17 50 13 7 37 21 25 31 28 18 30 27 24 16 15
31 38 52 46 1 29 41 12 39 24 10 45 13 22 42
8 10 33 18 39 49 29 43 51 2 35 19 27 41 12
48 13 33 39 30 47 32 24 12 9 42 1 18 41 51

output:

65
115
115
100
105

result:

ok 5 lines

Test #3:

score: 0
Accepted
time: 0ms
memory: 3712kb

input:

5
51 31 17 50 24 15 25 20 22 16 44 6 19 39 28
34 1 21 10 31 15 35 8 27 51 32 23 48 24 29
39 18 27 14 31 2 35 51 44 21 24 6 43 16 19
9 44 4 19 35 47 15 51 25 20 40 8 21 6 7
49 35 11 12 44 29 22 9 16 13 4 17 32 25 7

output:

100
125
115
75
85

result:

ok 5 lines

Test #4:

score: 0
Accepted
time: 0ms
memory: 3712kb

input:

5
16 41 30 6 5 39 22 1 29 42 32 49 40 27 21
39 14 32 48 6 37 23 35 13 52 43 2 24 38 45
49 42 38 18 47 52 30 15 16 1 26 31 28 6 40
47 31 22 45 49 46 36 17 35 48 38 33 13 16 20
41 17 9 34 25 21 8 18 22 24 4 20 26 15 42

output:

90
80
100
115
115

result:

ok 5 lines

Test #5:

score: 0
Accepted
time: 0ms
memory: 3712kb

input:

5
26 38 46 4 52 15 51 7 1 30 5 3 33 47 34
22 7 15 9 5 29 32 23 30 25 33 2 1 50 4
22 44 31 33 32 39 26 5 21 15 48 2 52 37 13
21 50 12 7 43 26 32 28 42 30 20 9 35 47 8
38 12 4 33 10 25 50 37 46 36 6 40 29 48 5

output:

100
65
100
120
115

result:

ok 5 lines

Test #6:

score: 0
Accepted
time: 0ms
memory: 3584kb

input:

5
32 51 43 23 30 17 36 37 48 22 46 41 20 1 42
49 29 40 4 19 46 13 39 8 12 47 38 16 32 34
37 34 45 36 10 26 33 21 46 35 39 13 41 27 19
51 15 42 35 27 52 18 1 44 37 26 39 33 32 8
31 50 52 24 37 17 26 2 20 13 1 38 9 49 51

output:

85
105
110
100
100

result:

ok 5 lines

Test #7:

score: 0
Accepted
time: 0ms
memory: 3712kb

input:

50
13 27 25 40 35 8 4 48 24 21 23 41 28 34 46
17 24 35 47 44 39 23 51 41 26 9 8 11 25 6
46 2 15 10 45 1 32 29 4 47 14 35 49 16 22
30 43 11 47 42 28 17 39 18 15 24 5 22 12 7
7 32 43 36 17 3 1 12 34 27 35 16 29 22 45
42 38 8 45 37 22 50 33 31 49 28 20 17 40 15
17 10 30 39 18 48 32 4 26 13 27 22 3 2 8
...

output:

25
0
110
205
160

result:

ok 5 lines

Test #8:

score: 0
Accepted
time: 0ms
memory: 3712kb

input:

50
23 24 41 38 31 36 34 2 39 37 47 43 35 3 32
9 4 29 18 35 23 40 43 41 52 45 48 25 37 28
3 37 25 2 16 44 1 31 23 42 22 40 48 30 6
39 38 46 20 9 18 37 42 29 17 21 23 7 50 12
43 12 19 21 31 22 38 5 2 36 45 17 18 51 13
29 52 39 31 16 21 9 15 4 48 43 41 24 20 30
28 50 51 17 10 41 40 48 13 45 24 18 11 43...

output:

30
10
170
135
155

result:

ok 5 lines

Test #9:

score: 0
Accepted
time: 0ms
memory: 3712kb

input:

50
29 37 4 16 38 19 24 34 21 11 26 48 3 39 35
26 10 13 49 9 12 14 1 2 28 11 43 47 18 19
30 43 40 29 12 22 46 6 36 35 20 2 32 23 45
51 27 39 10 2 24 52 14 7 4 38 36 25 47 21
36 19 2 3 45 47 44 5 51 30 49 35 46 6 11
32 37 30 12 34 13 45 35 42 41 8 52 16 27 2
38 30 12 13 28 19 31 26 36 5 51 34 35 41 25...

output:

10
130
25
215
120

result:

ok 5 lines

Test #10:

score: 0
Accepted
time: 2ms
memory: 3584kb

input:

50
52 16 47 32 18 9 10 29 48 22 28 36 14 6 20
49 11 33 23 40 10 31 20 46 5 38 48 13 44 50
25 15 35 47 33 41 32 9 7 24 10 11 17 21 23
8 50 24 43 28 47 13 44 29 2 17 30 5 7 18
30 8 10 5 20 33 14 25 24 37 17 9 23 41 35
26 35 51 43 8 3 50 32 33 37 52 23 19 1 42
41 33 6 19 47 17 36 49 18 27 32 48 29 50 1...

output:

20
10
180
120
170

result:

ok 5 lines

Test #11:

score: 0
Accepted
time: 1ms
memory: 3712kb

input:

50
13 49 39 9 33 12 32 20 37 8 48 42 3 26 17
34 30 13 39 17 23 51 24 41 31 47 28 52 25 50
29 26 40 31 14 47 51 35 36 13 42 52 5 17 46
12 3 51 43 47 41 35 42 15 39 49 25 6 50 1
38 45 52 4 40 44 17 36 2 5 25 18 32 23 1
25 22 18 37 35 49 32 8 10 30 11 46 15 29 47
31 41 18 4 8 24 1 47 9 40 27 37 26 34 2...

output:

165
160
90
85
0

result:

ok 5 lines

Test #12:

score: 0
Accepted
time: 3ms
memory: 3712kb

input:

100
40 49 2 41 4 1 10 13 37 8 36 42 19 14 38
5 28 40 23 25 29 12 46 27 38 49 19 6 33 7
16 50 8 46 40 5 51 21 25 1 19 45 6 30 31
9 40 37 4 41 47 26 16 3 32 35 44 7 27 52
16 38 20 36 19 31 5 51 25 18 43 6 22 3 33
47 10 16 26 30 14 24 22 51 32 34 52 17 23 8
27 16 48 22 17 6 25 46 50 38 47 15 28 20 4
25...

output:

95
10
135
75
185

result:

ok 5 lines

Test #13:

score: 0
Accepted
time: 1ms
memory: 3712kb

input:

100
7 44 43 37 47 49 8 25 22 5 40 35 18 33 41
28 16 14 30 24 27 11 41 6 23 33 12 39 50 13
26 30 10 4 32 45 15 52 46 51 39 40 7 47 17
12 43 38 26 9 44 51 11 16 23 32 21 27 15 37
50 4 22 1 37 25 24 49 26 28 9 39 7 14 17
43 10 39 45 36 9 37 28 46 6 3 25 8 51 34
12 38 35 17 42 30 37 44 48 33 47 28 5 36 ...

output:

130
10
160
150
50

result:

ok 5 lines

Test #14:

score: 0
Accepted
time: 5ms
memory: 3584kb

input:

100
20 18 36 15 1 52 30 16 13 48 37 8 11 38 42
26 31 35 14 50 21 46 27 38 32 52 41 12 25 28
36 26 23 18 38 43 21 15 3 52 29 12 41 24 8
7 20 24 10 21 47 30 41 29 3 45 16 4 8 18
43 11 40 22 45 51 39 52 15 26 12 34 14 28 25
31 36 27 4 6 9 19 49 26 12 2 21 7 42 32
12 15 52 1 49 21 6 13 19 37 7 50 33 3 2...

output:

10
145
20
165
160

result:

ok 5 lines

Test #15:

score: 0
Accepted
time: 1ms
memory: 3584kb

input:

100
37 36 49 23 34 22 51 31 48 26 21 25 6 44 33
2 32 3 35 11 18 40 46 47 26 45 7 44 13 8
28 45 26 34 50 6 2 11 40 3 13 10 32 47 44
6 51 39 20 38 43 37 34 49 40 52 28 27 36 5
39 23 46 37 50 45 43 24 20 5 36 41 8 32 30
26 2 39 40 1 24 21 31 11 49 12 23 9 3 20
38 46 17 47 13 25 30 36 48 14 40 32 43 8 4...

output:

140
10
155
30
165

result:

ok 5 lines

Test #16:

score: 0
Accepted
time: 2ms
memory: 3584kb

input:

100
1 46 18 40 7 44 51 27 41 48 14 33 32 11 2
27 30 5 15 28 1 42 17 33 3 26 22 51 23 11
47 43 38 52 17 48 33 2 1 28 46 24 27 36 41
3 43 17 40 32 50 38 23 5 33 35 10 7 41 8
33 44 26 35 8 10 31 47 3 32 36 1 51 17 49
21 15 29 12 4 2 43 51 31 36 45 49 33 9 32
33 21 7 6 47 27 26 37 30 8 22 12 41 44 50
15...

output:

10
10
100
220
160

result:

ok 5 lines

Test #17:

score: 0
Accepted
time: 1ms
memory: 3584kb

input:

48
41 31 16 6 15 24 1 50 10 19 13 44 4 20 18
45 39 24 51 43 1 44 35 17 29 49 19 13 23 52
41 4 21 29 38 16 45 15 27 37 44 24 25 9 31
38 32 27 51 19 21 11 6 30 10 49 14 13 24 35
44 20 38 9 40 3 11 47 25 23 19 52 12 15 41
41 34 25 30 52 44 29 47 35 38 22 3 9 28 46
18 1 10 25 19 37 41 46 31 44 47 30 52 ...

output:

5
10
125
205
155

result:

ok 5 lines

Test #18:

score: 0
Accepted
time: 4ms
memory: 3584kb

input:

90
7 29 39 34 14 41 44 21 50 11 36 26 35 10 13
45 34 1 3 28 41 50 39 48 36 16 19 46 10 25
14 17 41 9 27 28 20 43 6 42 15 21 1 5 7
50 34 40 13 15 7 26 16 2 5 21 11 24 30 3
8 46 15 20 34 38 32 9 1 39 44 4 51 12 7
36 24 49 48 23 17 33 38 41 19 26 9 7 5 22
48 30 16 47 43 33 5 2 49 45 9 19 50 29 15
18 8 ...

output:

200
5
0
155
140

result:

ok 5 lines

Test #19:

score: 0
Accepted
time: 0ms
memory: 3584kb

input:

26
19 31 43 8 27 37 47 35 44 9 22 51 41 11 5
51 10 15 34 22 8 38 27 16 3 19 35 49 17 26
34 52 49 42 36 10 35 31 29 17 23 22 27 28 40
10 5 52 43 13 20 37 35 49 19 42 4 41 23 11
43 42 39 29 15 33 52 12 6 46 8 11 2 51 36
45 1 22 17 40 29 41 37 20 15 43 49 31 32 47
50 5 48 40 42 11 23 37 2 44 14 4 29 19...

output:

185
10
70
90
145

result:

ok 5 lines

Test #20:

score: 0
Accepted
time: 0ms
memory: 3712kb

input:

10
1 10 27 51 39 12 29 9 47 15 30 25 32 42 41
5 14 46 44 29 45 24 51 1 39 7 8 16 31 35
51 24 37 50 36 7 41 35 2 48 45 31 3 6 21
39 26 6 51 24 50 35 42 7 28 23 36 15 31 16
29 20 39 12 17 52 38 37 28 14 10 2 18 25 22
28 38 6 17 44 13 14 10 41 49 2 29 51 21 15
17 31 1 51 39 36 20 5 21 42 26 2 19 16 50
...

output:

145
105
105
85
60

result:

ok 5 lines

Test #21:

score: 0
Accepted
time: 3ms
memory: 3712kb

input:

46
14 12 31 23 5 25 6 33 48 32 37 46 27 26 11
21 4 47 52 22 40 18 25 39 24 1 15 26 34 13
26 36 41 10 4 13 6 11 3 21 7 31 17 49 24
24 44 25 8 29 37 4 42 19 36 15 47 14 46 52
7 40 31 29 51 19 17 2 38 16 5 8 33 32 34
14 48 25 31 6 29 13 35 43 38 26 21 50 10 36
20 33 6 2 51 8 44 34 5 40 38 50 36 35 17
4...

output:

85
60
85
170
100

result:

ok 5 lines

Test #22:

score: 0
Accepted
time: 0ms
memory: 3712kb

input:

4
2 3 14 17 11 13 18 21 28 30 1 4 5 10 12
1 4 14 17 6 8 18 21 28 30 2 3 5 7 9
1 3 14 17 6 7 18 21 28 30 2 4 5 8 13
1 2 14 17 6 7 18 21 28 30 3 4 5 51 52

output:

165
55
80
100
100

result:

ok 5 lines

Test #23:

score: 0
Accepted
time: 0ms
memory: 3712kb

input:

1
15 49 28 30 1 14 51 9 18 21 10 11 12 13 52

output:

100
95
120
85
100

result:

ok 5 lines

Test #24:

score: 0
Accepted
time: 1ms
memory: 3584kb

input:

3
5 18 14 15 6 13 2 3 22 23 37 38 39 8 40
5 18 13 14 6 12 2 3 22 52 36 37 38 21 42
14 15 3 6 1 22 41 42 50 51 23 24 25 26 52

output:

120
95
85
100
100

result:

ok 5 lines

Test #25:

score: 0
Accepted
time: 0ms
memory: 3712kb

input:

1
44 40 16 30 5 39 18 15 31 2 6 7 8 51 52

output:

90
110
100
100
100

result:

ok 5 lines

Test #26:

score: 0
Accepted
time: 1ms
memory: 3584kb

input:

1
44 40 3 4 5 39 18 15 31 2 6 7 8 51 52

output:

90
110
100
100
100

result:

ok 5 lines

Test #27:

score: 0
Accepted
time: 0ms
memory: 3712kb

input:

3
44 40 3 4 5 39 18 15 31 2 6 7 8 51 52
44 40 16 30 5 39 18 15 31 2 6 7 8 51 52
44 40 16 30 5 39 18 15 31 2 6 7 8 51 52

output:

70
130
100
100
100

result:

ok 5 lines

Test #28:

score: 0
Accepted
time: 1ms
memory: 3712kb

input:

5
9 35 26 25 6 39 43 28 19 33 47 29 4 30 16
32 6 1 9 38 37 33 29 35 12 31 30 28 27 7
25 22 6 17 2 32 18 38 14 23 16 37 29 12 34
31 39 27 12 3 1 10 9 28 6 2 5 30 4 33
17 52 41 43 20 19 26 9 7 49 3 45 50 2 44

output:

70
80
125
120
105

result:

ok 5 lines

Test #29:

score: 0
Accepted
time: 1ms
memory: 3712kb

input:

10
49 30 43 41 10 20 36 7 11 46 38 34 21 17 31
24 42 5 33 11 36 13 52 31 40 39 4 21 22 1
47 23 46 8 16 25 4 26 14 52 45 22 7 21 17
1 31 22 21 12 6 23 37 14 10 24 18 30 39 36
5 23 14 24 10 39 25 13 31 8 7 17 20 26 22
2 28 11 31 32 8 12 9 52 4 33 13 51 39 1
17 31 27 26 21 19 29 25 15 39 16 33 38 35 24...

output:

100
30
80
140
150

result:

ok 5 lines

Test #30:

score: 0
Accepted
time: 0ms
memory: 3584kb

input:

20
5 4 34 12 32 33 36 2 31 6 28 9 10 13 38
32 23 30 24 25 38 20 28 39 17 35 14 22 37 26
21 7 32 27 34 35 24 29 10 37 17 31 18 13 38
43 46 14 37 41 33 15 29 38 19 35 48 26 40 30
35 50 5 8 1 39 17 2 22 15 9 26 19 33 31
15 46 16 25 6 2 50 20 45 1 8 26 12 14 24
18 33 37 14 29 23 35 25 36 26 16 17 32 30 ...

output:

140
45
95
130
90

result:

ok 5 lines

Test #31:

score: 0
Accepted
time: 0ms
memory: 3712kb

input:

30
1 14 18 3 5 4 10 8 9 13 6 23 17 20 21
43 29 46 28 25 47 31 24 33 18 27 44 35 41 49
15 6 10 19 4 7 8 5 18 24 20 17 9 14 3
44 18 4 25 15 46 1 50 5 16 43 22 19 41 45
21 23 1 11 9 16 7 10 24 15 20 26 22 5 17
50 49 42 46 47 40 10 9 1 6 41 52 43 51 8
47 9 11 32 1 27 4 51 19 31 29 7 39 18 3
7 25 41 12 5...

output:

75
10
175
60
180

result:

ok 5 lines

Test #32:

score: 0
Accepted
time: 0ms
memory: 3584kb

input:

40
51 46 29 45 41 2 47 6 35 4 42 5 36 11 27
29 2 35 22 41 44 8 34 48 24 21 25 19 26 33
32 17 20 48 45 35 24 34 14 44 43 37 40 18 30
3 26 52 10 2 15 31 4 45 32 46 27 25 20 48
36 31 6 9 10 29 32 3 34 4 11 30 8 28 12
26 38 23 11 31 39 2 34 49 44 12 29 21 7 47
44 45 20 42 52 47 16 15 21 23 19 24 26 14 2...

output:

40
10
160
140
150

result:

ok 5 lines

Test #33:

score: 0
Accepted
time: 4ms
memory: 3712kb

input:

50
16 3 12 4 32 33 43 29 1 46 27 45 10 25 5
45 48 29 35 51 37 52 34 38 46 41 30 50 47 28
45 19 16 20 3 32 9 31 14 10 52 11 21 6 17
9 17 33 7 36 3 11 41 24 27 34 50 19 2 25
14 43 31 46 42 3 7 23 40 37 33 19 52 22 17
8 1 27 21 36 33 17 39 34 32 2 9 13 11 15
28 48 36 35 16 22 24 47 51 14 27 39 34 42 37...

output:

80
10
95
180
135

result:

ok 5 lines

Test #34:

score: 0
Accepted
time: 0ms
memory: 3712kb

input:

70
7 8 27 5 40 52 49 20 25 19 47 34 26 35 22
6 12 7 2 13 4 37 34 8 23 22 24 31 35 20
1 52 32 38 4 26 20 33 41 29 30 13 8 16 43
20 45 1 21 12 10 39 31 24 46 30 28 4 13 5
37 48 44 45 35 46 19 14 3 40 15 13 18 51 27
24 21 17 49 44 42 50 45 8 2 7 16 25 41 40
29 41 42 45 33 48 27 34 36 47 38 39 51 28 30
...

output:

45
10
235
25
185

result:

ok 5 lines

Test #35:

score: 0
Accepted
time: 1ms
memory: 3584kb

input:

100
3 24 21 15 5 1 9 7 10 18 19 16 22 13 4
36 31 30 13 9 12 28 33 32 8 38 5 10 23 26
3 24 10 4 48 21 29 36 11 19 14 22 5 20 26
46 18 43 6 5 16 21 13 22 15 26 12 24 40 17
14 7 16 46 9 4 20 52 44 43 8 2 26 10 18
17 30 21 39 23 25 20 35 29 14 33 28 26 27 24
45 35 37 40 47 43 15 36 38 28 49 21 39 18 17
...

output:

85
10
125
140
140

result:

ok 5 lines

Test #36:

score: 0
Accepted
time: 7ms
memory: 3584kb

input:

300
38 46 44 18 20 40 51 17 15 52 6 22 12 8 26
7 10 17 35 21 6 33 8 12 2 13 38 11 34 15
12 3 34 10 5 6 25 14 11 28 4 26 16 20 37
15 24 33 46 22 48 8 2 20 49 41 1 12 17 21
8 38 5 45 37 42 6 7 2 48 41 12 32 52 29
44 33 32 40 43 50 12 1 11 48 13 16 21 10 39
17 11 4 18 16 25 3 2 1 24 9 15 13 7 12
25 19 ...

output:

10
10
0
0
480

result:

ok 5 lines

Test #37:

score: 0
Accepted
time: 11ms
memory: 3584kb

input:

500
11 29 38 5 30 34 32 8 1 35 9 7 33 39 13
16 38 3 43 31 25 44 24 23 2 4 35 10 34 26
34 47 50 48 33 28 42 31 29 41 30 43 27 36 44
31 5 27 8 10 29 9 2 6 7 13 38 4 37 1
17 22 44 20 16 4 25 51 5 14 24 47 45 21 52
9 6 33 5 10 25 22 4 7 29 47 39 49 34 42
11 42 7 52 4 1 49 2 43 10 51 46 40 13 5
25 19 6 5...

output:

80
10
0
0
410

result:

ok 5 lines

Test #38:

score: 0
Accepted
time: 14ms
memory: 3712kb

input:

1000
28 44 51 37 47 50 38 12 49 43 9 7 45 8 2
16 25 15 39 19 7 31 22 30 18 12 9 1 32 13
24 28 16 12 43 38 42 20 34 48 37 52 39 40 32
36 29 48 35 44 5 41 8 52 3 33 6 37 4 12
10 5 40 6 9 51 44 45 49 8 2 13 12 4 1
16 36 28 37 26 18 34 52 39 51 33 5 27 21 40
19 22 3 46 23 18 29 30 28 5 24 13 27 37 44
12...

output:

0
0
0
0
500

result:

ok 5 lines