QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#711112#1965. TriotamthegodWA 2ms4408kbC++233.6kb2024-11-05 00:32:482024-11-05 00:32:49

Judging History

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

  • [2024-11-05 00:32:49]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:4408kb
  • [2024-11-05 00:32:48]
  • 提交

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;
}
int get(int x, int i)
{
    return x % (pw[i] * 10) / pw[i] * pw[i];
}
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 - get(v, pos[t]));
                    }
                }
                for(int v : tmp)
                {
                    //cout << v << '\n';
                }
                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: 4040kb

input:

4
1234
2345
3456
4567

output:

4

result:

ok single line: '4'

Test #2:

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

input:

9
1299
2399
3499
4599
5699
6799
7899
8999
9199

output:

84

result:

ok single line: '84'

Test #3:

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

input:

9
1239
2349
3459
4569
5679
6789
7899
8919
9129

output:

84

result:

ok single line: '84'

Test #4:

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

input:

9
1999
2999
3999
4999
5999
6999
7999
8999
9999

output:

84

result:

ok single line: '84'

Test #5:

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

input:

9
1234
2345
3456
4567
5678
6789
7891
8912
9123


output:

84

result:

ok single line: '84'

Test #6:

score: -100
Wrong Answer
time: 2ms
memory: 4408kb

input:

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

output:

312

result:

wrong answer 1st lines differ - expected: '168', found: '312'