QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#526970#1965. Triosroid_03#AC ✓1404ms3856kbC++143.8kb2024-08-22 03:54:182024-08-22 03:54:19

Judging History

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

  • [2024-08-22 03:54:19]
  • 评测
  • 测评结果:AC
  • 用时:1404ms
  • 内存:3856kb
  • [2024-08-22 03:54:18]
  • 提交

answer



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

#define INF 1e18
#define endl "\n"
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define PI atan(1)*4
#define set_bits __builtin_popcountllO
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
#define vll vector<ll>
#define pll pair<ll,ll>
#define rvsort(a) sort(all(a),greater<int>())
#define read(a,n) for(int i = 0 ; i < n ; i ++){ cin >> a[i];}
#define printv(a) for(auto it: a){cout << it << " ";} cout << endl;
#define ms(arr, v) memset(arr, v, sizeof(arr))

typedef int ll;
typedef unsigned long long ull;
typedef long double lld;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#ifndef ONLINE_JUDGE
#include "/Users/templates/debug.h"
#else
#define dbg(x...)
#endif
/*---------------------------------------------------------------------------------------------------------------------------*/
ll gcd(ll a, ll b) {if (b > a) {return gcd(b, a);} if (b == 0) {return a;} return gcd(b, a % b);}
ll expo(ll a, ll b, ll mod) {ll res = 1; while (b > 0) {if (b & 1)res = (res * a) % mod; a = (a * a) % mod; b = b >> 1;} return res;}
void extendgcd(ll a, ll b, ll*v) {if (b == 0) {v[0] = 1; v[1] = 0; v[2] = a; return ;} extendgcd(b, a % b, v); ll x = v[1]; v[1] = v[0] - v[1] * (a / b); v[0] = x; return;} //pass an arry of size1 3
ll mminv(ll a, ll b) {ll arr[3]; extendgcd(a, b, arr); return arr[0];} //for non prime b
ll mminvprime(ll a, ll b) {return expo(a, b - 2, b);}
void google(int t) {cout << "Case #" << t << ": ";}
vector<ll> sieve(int n) {int*arr = new int[n + 1](); vector<ll> vect; for (int i = 2; i <= n; i++)if (arr[i] == 0) {vect.push_back(i); for (int j = 2 * i; j <= n; j += i)arr[j] = 1;} return vect;}
ll phin(ll n) {ll number = n; if (n % 2 == 0) {number /= 2; while (n % 2 == 0) n /= 2;} for (ll i = 3; i <= sqrt(n); i += 2) {if (n % i == 0) {while (n % i == 0)n /= i; number = (number / i * (i - 1));}} if (n > 1)number = (number / n * (n - 1)) ; return number;} //O(sqrt(N))
ll uid(ll l, ll r) {return uniform_int_distribution<ll>(l, r)(rng);} 
/*--------------------------------------------------------------------------------------------------------------------------*/
//const int mod = 1e9 + 7;
//const int mod = 998244353; 


void solve()
{
    ll n; cin >> n;
    vll a(n); read(a,n);
    vll cnt(10000);
    ll ans = 0;
    ll powl[4] = {1, 10, 100, 1000};
    vector<string> st(n);
    for(int i = 0 ; i < n ; i ++) st[i] = to_string(a[i]);
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            vector<pll> vals;
            vals.pb({0, 1});
            for (int d = 0; d < 4; d++) {
                if (st[i][4-d-1] != st[j][4-d-1]) {
                    vector<pll> tmp;
                    for (auto [x, y] : vals) {
                        tmp.pb({x, y});
                        tmp.pb({x + (st[i][4-d-1]-'0') * powl[d], -y});
                        tmp.pb({x + (st[j][4-d-1]-'0')* powl[d], -y});
                    }
                    vals = tmp;
                } else {
                    for (auto &[x, y] : vals) {
                        x += powl[d] * (st[i][4-d-1]-'0');
                    }
                }
            }
            for (auto [x, y] : vals) {
                ans += cnt[x] * y;
            }
        }
        for (int s = 0; s < (1LL<< 4); s++) {
            ll x = 0;
            for (int d = 0; d < 4; d++) {
                x += (s&(1LL<<d) ? st[i][4-d-1]-'0' : 0) * powl[d];
            }
            cnt[x]++;
        }
    }
    cout << ans << endl;
}

int main() {

ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);


ll t = 1;
// cin >> t;
for(int i = 1 ; i <= t ; i++){
//google(i);
solve();
}
return 0;
}









Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4
1234
2345
3456
4567

output:

4

result:

ok single line: '4'

Test #2:

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

input:

9
1299
2399
3499
4599
5699
6799
7899
8999
9199

output:

84

result:

ok single line: '84'

Test #3:

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

input:

9
1239
2349
3459
4569
5679
6789
7899
8919
9129

output:

84

result:

ok single line: '84'

Test #4:

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

input:

9
1999
2999
3999
4999
5999
6999
7999
8999
9999

output:

84

result:

ok single line: '84'

Test #5:

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

input:

9
1234
2345
3456
4567
5678
6789
7891
8912
9123


output:

84

result:

ok single line: '84'

Test #6:

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

input:

18
1211
2311
3411
4511
5611
6711
7811
8911
9111
1222
2322
3422
4522
5622
6722
7822
8922
9122

output:

168

result:

ok single line: '168'

Test #7:

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

input:

17
1211
2311
3411
4511
5611
6711
7811
8911
9111
1231
2341
3451
4561
5671
6781
7891
9121

output:

336

result:

ok single line: '336'

Test #8:

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

input:

81
1211
2311
3411
4511
5611
6711
7811
8911
9111
1222
2322
3422
4522
5622
6722
7822
8922
9122
1233
2333
3433
4533
5633
6733
7833
8933
9133
1244
2344
3444
4544
5644
6744
7844
8944
9144
1255
2355
3455
4555
5655
6755
7855
8955
9155
1266
2366
3466
4566
5666
6766
7866
8966
9166
1277
2377
3477
4577
5677
67...

output:

43848

result:

ok single line: '43848'

Test #9:

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

input:

17
3433
3443
3444
3434
3333
3334
3343
3344
4333
4343
4334
4344
4433
4434
4444
4443
5678

output:

8

result:

ok single line: '8'

Test #10:

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

input:

21
1111
1113
1131
1133
1222
1312
1321
1323
1332
2122
2322
3112
3121
3123
3132
3222
3311
3313
3331
3333
4567

output:

28

result:

ok single line: '28'

Test #11:

score: 0
Accepted
time: 89ms
memory: 3816kb

input:

500
5225
6396
8284
5729
9576
3159
1831
9314
5674
4164
5166
5513
1765
8333
9921
7856
3789
6129
3882
1462
1322
5932
6859
1794
6426
8336
3265
2938
4487
7143
3653
4218
7814
3521
3349
5331
3486
7264
5385
8724
7421
5736
9875
9432
1588
5758
4319
9649
4224
6841
9639
1774
1551
9761
1944
3979
7682
5599
4289
7...

output:

5075198

result:

ok single line: '5075198'

Test #12:

score: 0
Accepted
time: 89ms
memory: 3740kb

input:

500
5114
6269
8111
5597
9326
2942
1773
8955
5577
4165
4969
5388
1691
8159
9766
7686
3789
5829
3855
1431
1283
5781
6655
1762
6292
8183
3156
2837
4417
6868
3591
4189
7629
3451
3241
5228
3414
6881
5367
8384
7166
5612
9755
9147
1526
5633
4239
9385
4191
6575
9345
1743
1447
9623
1884
3978
7438
5517
4231
7...

output:

5084517

result:

ok single line: '5084517'

Test #13:

score: 0
Accepted
time: 353ms
memory: 3704kb

input:

1000
5643
3673
9624
6633
5355
6586
9219
8148
9533
7777
2984
9365
5932
4617
5553
6716
2312
3599
2349
1216
9483
3558
3846
1353
3675
4621
7556
1842
9698
3958
2178
2595
7377
8579
1952
7632
1999
8277
3295
9384
7845
3467
5546
5266
5962
8118
8261
5395
2597
8256
7546
1343
1248
8936
1394
2478
9247
3392
9397
...

output:

40686935

result:

ok single line: '40686935'

Test #14:

score: 0
Accepted
time: 355ms
memory: 3828kb

input:

1000
5659
3899
9639
6658
5344
6624
9339
8138
9619
7818
3314
9459
5967
4695
5557
6692
2422
3792
2451
1228
9568
3755
4149
1383
3915
4696
7571
1875
9687
4223
2324
2669
7413
8624
2158
7668
2244
8275
3467
9487
7874
3624
5555
5258
5982
8114
8255
5376
2674
8242
7558
1382
1254
9152
1443
2535
9355
3556
9489
...

output:

40589947

result:

ok single line: '40589947'

Test #15:

score: 0
Accepted
time: 350ms
memory: 3688kb

input:

1000
5565
3799
9621
6574
5284
6539
9171
8136
9555
7837
3234
9315
5885
4634
5482
6647
2465
3686
2491
1242
9468
3622
3897
1433
3816
4637
7538
2117
9689
3972
2415
2664
7381
8532
2235
7657
2317
8247
3414
9349
7865
3495
5481
5196
5899
8128
8217
5322
2678
8194
7533
1425
1279
8812
1485
2551
9188
3457
9351
...

output:

40686926

result:

ok single line: '40686926'

Test #16:

score: 0
Accepted
time: 1393ms
memory: 3740kb

input:

2000
5699
2343
5288
9952
3128
8562
7628
4456
8712
4359
8217
8242
3426
2742
7267
9136
9277
6815
1671
1181
9432
9411
7289
5719
2345
6542
4235
8919
8122
9981
1622
1782
4164
4668
1537
4267
1562
4532
6391
7882
4371
2196
8633
6411
6452
6991
6275
8334
8679
6972
7141
9822
1191
4845
7199
8737
8495
7826
7456
...

output:

326702860

result:

ok single line: '326702860'

Test #17:

score: 0
Accepted
time: 1394ms
memory: 3788kb

input:

2000
5661
2399
5315
9953
3236
8494
7548
4468
8647
4383
8171
8184
3496
2848
7227
9141
9287
6766
1725
1193
9432
9425
7256
5682
2414
6525
4255
8886
7988
9982
1648
1784
4174
4677
1555
4313
1585
4543
6337
7848
4398
2268
8568
6343
6413
6977
6237
8253
8622
6958
7121
9838
1226
4842
7182
8685
8443
7759
7378
...

output:

326499935

result:

ok single line: '326499935'

Test #18:

score: 0
Accepted
time: 1388ms
memory: 3704kb

input:

2000
5794
2444
5427
9941
3263
8588
7712
4641
8699
4546
8321
8337
3569
2844
7368
9155
9276
6875
1812
1168
9429
9413
7394
5816
2445
6663
4444
8919
8232
9982
1735
1883
4362
4851
1667
4476
1691
4716
6515
7982
4564
2325
8656
6519
6582
7191
6397
8421
8688
7168
7255
9825
1177
5113
7332
8731
8543
7886
7527
...

output:

326783211

result:

ok single line: '326783211'

Test #19:

score: 0
Accepted
time: 1404ms
memory: 3740kb

input:

2000
5752
2465
5387
9897
3214
8513
7635
4624
8653
4498
8219
8222
3538
2836
7268
8959
9242
6834
1747
1181
9414
9372
7295
5758
2474
6619
4374
8847
8134
9966
1692
1831
4322
4849
1588
4432
1645
4671
6465
7886
4539
2315
8581
6473
6526
7123
6352
8281
8617
7114
7167
9749
1196
4998
7224
8675
8462
7827
7433
...

output:

327038446

result:

ok single line: '327038446'

Test #20:

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

input:

1
1111

output:

0

result:

ok single line: '0'

Test #21:

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

input:

2
1111
9783

output:

0

result:

ok single line: '0'

Test #22:

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

input:

3
1111
1122
1211

output:

0

result:

ok single line: '0'

Test #23:

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

input:

4
1111
1122
1211
9876

output:

0

result:

ok single line: '0'

Test #24:

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

input:

8
1111
1112
1121
1122
1211
1212
1221
1222

output:

0

result:

ok single line: '0'

Test #25:

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

input:

12
1111
1112
1121
1122
1211
1212
1221
1222
2111
2112
2121
2122

output:

0

result:

ok single line: '0'

Test #26:

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

input:

16
3433
3443
3444
3434
3333
3334
3343
3344
4333
4343
4334
4344
4433
4434
4444
4443

output:

0

result:

ok single line: '0'

Test #27:

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

input:

20
1111
1113
1131
1133
1222
1312
1321
1323
1332
2122
2322
3112
3121
3123
3132
3222
3311
3313
3331
3333

output:

0

result:

ok single line: '0'

Test #28:

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

input:

3
1111
1112
1113

output:

1

result:

ok single line: '1'

Test #29:

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

input:

3
1111
1122
1133

output:

1

result:

ok single line: '1'

Test #30:

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

input:

3
1111
1222
1333

output:

1

result:

ok single line: '1'

Test #31:

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

input:

3
1234
2345
3456

output:

1

result:

ok single line: '1'