QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#711104 | #1965. Trio | tamthegod | WA | 1ms | 4072kb | C++23 | 3.4kb | 2024-11-05 00:27:33 | 2024-11-05 00:27:38 |
Judging History
answer
#include<bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int maxN = 2000 + 5;
const int mod = 1e9 + 7;
const ll oo = 1e18;
int n;
string s[maxN];
int f[maxN][10000];
vector<int> val;
int pw[4] = {1, 10, 100, 1000};
void ReadInput()
{
cin >> n;
for(int i=1; i<=n; i++)
{
cin >> s[i];
val.pb(stoi(s[i]));
}
sort(val.begin(), val.end());
val.erase(unique(val.begin(), val.end()), val.end());
for(int i=n; i>=1; i--)
{
for(int j=0; j<10000; j++)
{
bool ok = true;
string cur = to_string(j);
while(cur.size() < 4) cur = '0' + cur;
for(int t=0; t<4; t++)
{
if(cur[t] == '0') continue;
if(s[i][t] != cur[t])
{
ok = false;
break;
}
}
f[i][j] = f[i + 1][j] + ok;
}
}
}
int chk(char a, char b)
{
if(a == b) return a - '0';
return -1;
}
void Solve()
{
int res = 0;
for(int i=1; i<=n; i++)
for(int j=i+1; j<n; j++)
{
int val = 0;
vector<int> pos;
for(int t=0; t<4; t++)
{
if(chk(s[i][t], s[j][t]) == -1)
{
val = val * 10;
pos.pb(t);
}
else val = val * 10 + (s[i][t] - '0');
}
int sum = f[j + 1][val];
vector<int> vc;
vc.pb(0);
for(int t=0; t<pos.size(); t++)
{
vector<int> tmp;
for(int v : vc)
{
tmp.pb(v + (s[i][pos[t]] - '0') * pw[3 - pos[t]]);
tmp.pb(v + (s[j][pos[t]] - '0') * pw[3 - pos[t]]);
}
swap(vc, tmp);
}
for(int mask=1; mask<(1<<(pos.size())); mask++)
{
vector<int> tmp;
for(int t=0; t<pos.size(); t++)
{
if((mask >> t & 1))
{
for(int &v : vc)
tmp.pb(v - (v / pw[pos[t]] * pw[pos[t]]));
}
}
sort(tmp.begin(), tmp.end());
tmp.erase(unique(tmp.begin(), tmp.end()), tmp.end());
if(__builtin_popcount(mask) & 1)
{
for(int v : tmp)
{
sum -= f[j + 1][val + v];
}
}
else
{
for(int v : tmp)
sum += f[j + 1][val + v];
}
}
res += sum;
}
cout << res;
}
#define taskname "sol"
int32_t main()
{
if (fopen(taskname ".inp", "r"))
{
freopen(taskname ".inp", "r", stdin);
// freopen(taskname ".out", "w", stdout);
}
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int T = 1;
//cin >> T;
for(int itest=1; itest<=T; itest++)
{
ReadInput();
Solve();
}
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 4072kb
input:
4 1234 2345 3456 4567
output:
4
result:
ok single line: '4'
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 4052kb
input:
9 1299 2399 3499 4599 5699 6799 7899 8999 9199
output:
0
result:
wrong answer 1st lines differ - expected: '84', found: '0'