QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#711096#1965. TriotamthegodWA 1ms4124kbC++233.3kb2024-11-05 00:24:202024-11-05 00:24:20

Judging History

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

  • [2024-11-05 00:24:20]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:4124kb
  • [2024-11-05 00:24:20]
  • 提交

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 = vc;
                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]]));
                    }
                }

                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: 3848kb

input:

4
1234
2345
3456
4567

output:

4

result:

ok single line: '4'

Test #2:

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

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: 4048kb

input:

9
1239
2349
3459
4569
5679
6789
7899
8919
9129

output:

84

result:

ok single line: '84'

Test #4:

score: -100
Wrong Answer
time: 0ms
memory: 4124kb

input:

9
1999
2999
3999
4999
5999
6999
7999
8999
9999

output:

-84

result:

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