QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#325293#5607. Cribbage On Steroidsape_packWA 1ms3832kbC++142.8kb2024-02-11 07:16:372024-02-11 07:16:38

Judging History

你现在查看的是最新测评结果

  • [2024-02-11 07:16:38]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3832kb
  • [2024-02-11 07:16:37]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = a; i >= b; i--)
#define F0Rd(i,a) for (int i = a; i >= 0; i--)
#define FORit(it,a) for (auto it = a.begin(); it != a.end(); it++)
#define trav(a,x) for (auto& a: x)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define alla(arr, sz) arr, arr + sz

const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 }; // for every grid problem!!
const ll linf = 4*1e18;
const int inf = 1000000007;

namespace io {
    void setIn(string s) { freopen(s.c_str(),"r",stdin); }
    void setOut(string s) { freopen(s.c_str(),"w",stdout); }
    void setIO(string s = "") {
        ios_base::sync_with_stdio(0); cin.tie(0); // fast I/O
        if (sz(s)) { setIn(s+".in"), setOut(s+".out"); } // for USACO
    }
}

using namespace io;

#define DEBUG 0

void solve() {
    int n; cin >> n; 
    map<char, int> m_sum, m; 
    FOR(i,2,10) m_sum[i+'0'] = i; 
    m_sum['A'] = 1; 
    m_sum['T'] = 10; 
    m_sum['J'] = 10; 
    m_sum['Q'] = 10; 
    m_sum['K'] = 10; 
    FOR(i,2,10) m[i+'0'] = i; 
    m['A'] = 1; 
    m['T'] = 10; 
    m['J'] = 11; 
    m['Q'] = 12; 
    m['K'] = 13; 

    vi v; 
    map<int, int> freq_sum, freq; 
    F0R(i,n) {
        char c; cin>> c;
        v.pb(m_sum[c]);
        // freq_sum[m_sum[c]]++; 
        freq[m[c]]++;
    }

    ll ans = 0; 
    FORit(it,freq) {
        ans += (it->second -1)*it->second/2;
    }
    ans *= 2;

    for (auto it = freq.begin(); it != freq.end(); ) {
        auto tmp = it; tmp++; 
        int cur = it->second, val = it->first+1; 
        int cnt = 1; 
        if (tmp == freq.end()) cur = 0; 
        while(tmp != freq.end()) {
            if (tmp->first != val) {
                if (cnt <= 2) cur = 0; 
                it = tmp;
                break;
            }
            else {
                cur *= tmp->second; 
                val++; 
                cnt++; 
                tmp++; 
                if (tmp == freq.end() && cnt <= 2) cur = 0; 
            }
        }
        if (tmp == freq.end()) it = freq.end(); 
        ans += cur*cnt; 
    }

    ll dp[n+1][16]; memset(dp,0,sizeof dp);
    dp[0][0] = 1; 
    FOR(i,1,n+1) F0R(j,16) {
        dp[i][j] += dp[i-1][j];
        if (j-v[i-1] >= 0) dp[i][j] += dp[i-1][j-v[i-1]];
    }

    cout << ans + dp[n][15]*2;

}

int main() {
  #if DEBUG
  setIn("test.in");
  #else
  setIO();
  #endif

  int t;
  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: 3592kb

input:

5
4 5 6 5 5

output:

23

result:

ok single line: '23'

Test #2:

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

input:

13
A 2 3 4 5
6 7 8 9 T
J Q K

output:

71

result:

ok single line: '71'

Test #3:

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

input:

10
2 2 3 4 5 8 9 T J Q

output:

45

result:

ok single line: '45'

Test #4:

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

input:

5
5 5 5 5 J

output:

28

result:

ok single line: '28'

Test #5:

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

input:

5
5 5 5 5 5

output:

40

result:

ok single line: '40'

Test #6:

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

input:

11
A 2 3 5 6 7 8 T J Q K

output:

41

result:

ok single line: '41'

Test #7:

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

input:

20
A 2 3 4 5
A 2 3 4 5
A 2 3 4 5
A 2 3 4 5

output:

20308

result:

ok single line: '20308'

Test #8:

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

input:

7
9 6 5 A 4 7 8

output:

16

result:

ok single line: '16'

Test #9:

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

input:

11
Q K
2 2 2
3 3 3
A A
4

output:

224

result:

ok single line: '224'

Test #10:

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

input:

100
A A A A A A A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A A A A A

output:

506676942699987180

result:

ok single line: '506676942699987180'

Test #11:

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

input:

100
5 5 5 5 5 5 5 5 5 5
5 5 5 5 5 5 5 5 5 5
5 5 5 5 5 5 5 5 5 5
5 5 5 5 5 5 5 5 5 5
5 5 5 5 5 5 5 5 5 5
5 5 5 5 5 5 5 5 5 5
5 5 5 5 5 5 5 5 5 5
5 5 5 5 5 5 5 5 5 5
5 5 5 5 5 5 5 5 5 5
5 5 5 5 5 5 5 5 5 5

output:

333300

result:

ok single line: '333300'

Test #12:

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

input:

5
K J 2 6 8

output:

0

result:

ok single line: '0'

Test #13:

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

input:

7
T J J J Q K K

output:

32

result:

ok single line: '32'

Test #14:

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

input:

5
J Q K A 2

output:

3

result:

ok single line: '3'

Test #15:

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

input:

14
5 5
A 4
2 3
A 4
2 3
T J Q K

output:

438

result:

ok single line: '438'

Test #16:

score: -100
Wrong Answer
time: 1ms
memory: 3568kb

input:

100
A T 4 K K J T 7 4 T Q A 5 K 8 T Q J K 5 3 8 A 9 3 4 7 J 5 7 K J 7 9 3 T 8 9 8 2 8 6 7 J T 6 6 4 5 K 9 6 5 K 5 J T A 4 3 A K 5 T Q T 6 K T 8 Q J K Q 8 A 6 9 5 7 K 3 2 5 Q J 4 T 2 7 2 9 2 T 9 4 5 9 5 5

output:

1451200586

result:

wrong answer 1st lines differ - expected: '2440992624714', found: '1451200586'