QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#325113 | #5614. Simple Solitaire | tom0727 | WA | 1ms | 3768kb | C++20 | 5.3kb | 2024-02-11 04:19:56 | 2024-02-11 04:19:56 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#if __cplusplus >= 201103L
struct pairhash {
static uint64_t splitmix64(uint64_t x) {
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
template<class T, class U>
size_t operator() (const pair<T,U> &p) const {
static const uint64_t FIXED_RANDOM = (uint64_t)chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(p.first + FIXED_RANDOM) ^ splitmix64(p.second+ FIXED_RANDOM);
}
};
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM = (uint64_t)chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());
inline int randint(int l, int r) {
return uniform_int_distribution<int>(l,r)(rng);
}
inline double randdouble(double l, double r) {
return uniform_real_distribution<double>(l,r)(rng);
}
inline long long randll(long long l, long long r) {
mt19937_64 rng2((uint32_t)chrono::steady_clock::now().time_since_epoch().count());
return uniform_int_distribution<long long>(l, r)(rng2);
}
#endif
#ifndef ONLINE_JUDGE
# define LOG(x) (cerr << #x << " = " << (x) << endl)
#else
# define LOG(x) 0
#endif
#define fastio ios::sync_with_stdio(false); cin.tie(0);
#define ll long long
#define ull unsigned long long
#define ll128 __int128_t
#define PI 3.14159265358979323846
#define abs(a) ((a>0)?a:-(a))
#define pii pair<int,int>
#define pll pair<ll,ll>
const long double pi = acos(-1.0);
const long double eps = (double)1e-10;
// const int mod = 1e9+7;
int mod;
template<class T>
T qpow(T a, int b) {
T res = 1;
while (b) {
if (b & 1) res *= a;
a *= a;
b >>= 1;
}
return res;
}
int norm(int x) {
if (x < 0) {
x += mod;
}
if (x >= mod) {
x -= mod;
}
return x;
}
struct Z {
int x;
Z(int x = 0) : x(norm(x)) {}
Z(ll x) : x(norm((int)(x % mod))) {}
int val() const {
return x;
}
Z operator-() const {
return Z(norm(mod - x));
}
Z inv() const {
assert(x != 0);
return qpow(*this, mod - 2);
}
Z &operator*=(const Z &rhs) {
x = (int)((ll)(x) * rhs.x % mod);
return *this;
}
Z &operator+=(const Z &rhs) {
x = norm(x + rhs.x);
return *this;
}
Z &operator-=(const Z &rhs) {
x = norm(x - rhs.x);
return *this;
}
Z &operator/=(const Z &rhs) {
return *this *= rhs.inv();
}
friend Z operator*(const Z &lhs, const Z &rhs) {
Z res = lhs;
res *= rhs;
return res;
}
friend Z operator+(const Z &lhs, const Z &rhs) {
Z res = lhs;
res += rhs;
return res;
}
friend Z operator-(const Z &lhs, const Z &rhs) {
Z res = lhs;
res -= rhs;
return res;
}
friend Z operator/(const Z &lhs, const Z &rhs) {
Z res = lhs;
res /= rhs;
return res;
}
friend std::istream &operator>>(std::istream &is, Z &a) {
ll v;
is >> v;
a = Z(v);
return is;
}
friend std::ostream &operator<<(std::ostream &os, const Z &a) {
return os << a.val();
}
};
const int maxn = 1001;
const int maxm = 1e6+5;
vector<string> vec;
int cmp(int i, int j) {
if (vec[i][0] == vec[j][0]) return 4;
if (vec[i][1] == vec[j][1]) return 2;
return 0;
}
bool check() {
int n = vec.size();
for (int i = n-1; i >= 0; i--) {
int j = i-3;
if (j >= 0) {
int res = cmp(i, j);
if (res == 4) {
vector<string> tmp;
for (int k = 0; k < j; k++) {
tmp.push_back(vec[k]);
}
for (int k = i+1; k < n; k++) {
tmp.push_back(vec[k]);
}
vec = tmp;
return 1;
}
if (res == 2) {
vector<string> tmp;
for (int k = 0; k < j; k++) {
tmp.push_back(vec[k]);
}
for (int k = j+1; k < i; k++) {
tmp.push_back(vec[k]);
}
for (int k = i+1; k < n; k++) {
tmp.push_back(vec[k]);
}
vec = tmp;
return 1;
}
}
}
return 0;
}
int main() {
for (int i = 1; i <= 52; i++) {
string x; cin >> x;
// LOG(x);
vec.push_back(x);
while (check()) {}
}
cout << vec.size() << " ";
for (string x : vec) cout << x << " ";
cout << "\n";
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3768kb
input:
TC 2C 6C TS KC QS QC 3C KD 8D JH JS KH 5D JD 2S 8S AS 9S 3D 5H 9C AH 4D 4C KS JC 4S 7S 6D 2H 7C 8C 7D AD 7H TH 2D QH 8H 9H 5C TD 3S 6H 3H QD 5S 9D 4H 6S AC
output:
2 3S 9D
result:
ok single line: '2 3S 9D '
Test #2:
score: 0
Accepted
time: 1ms
memory: 3760kb
input:
TH 2C 8H AS JH JS TS QC KS 3S JC 4D AH QS 2S 5S 3D 7C 4H AD 5C 7S 6C 6S 9C 5D 8D 9H 7H 3H KD KH 4C 8S QD 2D 8C QH KC TC 2H 4S 6H 5H 3C TD 6D JD AC 9S 7D 9D
output:
6 KC 4S 6H TD AC 9S
result:
ok single line: '6 KC 4S 6H TD AC 9S '
Test #3:
score: -100
Wrong Answer
time: 1ms
memory: 3608kb
input:
3H 8D 9H 4S 7H KC 6H 4D 4H 5H TS 2C JH QD QH 6C TD KD 3S KS TC 8S KH 2D 9D 9C QS 7D JS 5C 2H AS 5S 5D 4C 7C 8C AC 3C 6D 7S 8H AD 3D JC 2S 6S QC TH JD AH 9S
output:
12 KH AS 5S 5D 7C 3D 2S 6S TH JD AH 9S
result:
wrong answer 1st lines differ - expected: '12 TS AS 5S 5D 7C 3D 2S 6S TH JD AH 9S', found: '12 KH AS 5S 5D 7C 3D 2S 6S TH JD AH 9S '