QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#122306#957. Assignment Problemutshab1618WA 1ms3504kbC++202.2kb2023-07-10 00:08:442023-07-10 00:08:47

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-10 00:08:47]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3504kb
  • [2023-07-10 00:08:44]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T> using ordered_set =tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
// ordered_set.find_by_order(k) returns the iterator to kth element
// ordered_set.order_of_key(k) returns the number of elements strictly less than k */
#define watch(x) cerr << "\n" << (#x) << " is " << (x) << endl
#define fastio ios_base::sync_with_stdio(0)
#define flush_off cin.tie(0)
#define mod 1000000007
#define ganja 998244353

int fact(int n)
{
    if(!n) return 1;
    return (fact(n-1)*n);
}



void solve()
{
    int m,n;
    cin>>n>>m;
    int arr[m][n];
    for(int i=0; i<m; ++i)
    {
        for(int j=0; j<n; ++j)
        {
            cin>>arr[i][j];
            --arr[i][j];
        }
    }

    int par[m];
    for(int i=0; i<m; ++i) par[i] = i;
    int cases = fact(m);
    int is_available[n],promising[n];
    memset(is_available,0,sizeof(is_available));
    memset(promising,0,sizeof(promising));
    int cnt = 0;
    while(cases--)
    {
        vector<int>tmp;
        for(auto i:par)
        {
            for(int j=0; j<n; ++j)
            {
                if(!is_available[arr[i][j]])
                {
                    is_available[arr[i][j]] = 1;
                    if(!promising[arr[i][j]])
                    {
                        promising[arr[i][j]] = 1;
                        ++cnt;
                        tmp.push_back(arr[i][j]);
                    }
                    break;
                }
            }
        }

        for(auto i:tmp) is_available[i] = 0;
        tmp.clear();

        next_permutation(par,par+m);
    }

    cout<<cnt<<endl;
    for(int i=0; i<n; ++i)
    {
        if(promising[i]) cout<<i+1<<' ';
    }

    cout<<endl;

}

int main()
{
    fastio;
    flush_off; //turn this off if cout needs to be flushed
    #ifndef ONLINE_JUDGE
        freopen("Error.txt", "w", stderr);
    #endif
    int t=1;
    // cin>>t;
    while(t--) solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3388kb

input:

4 2
1 2 4 3
1 3 4 2

output:

3
1 2 3 

result:

ok 4 number(s): "3 1 2 3"

Test #2:

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

input:

4 2
1 4 3 2
2 3 4 1

output:

2
1 2 

result:

ok 3 number(s): "2 1 2"

Test #3:

score: -100
Wrong Answer
time: 1ms
memory: 3504kb

input:

10 5
3 5 10 9 8 7 4 1 6 2
3 4 5 8 1 6 2 9 7 10
2 9 8 3 1 5 10 6 7 4
6 8 4 9 2 7 3 5 1 10
10 3 6 5 9 1 4 2 8 7

output:

10
1 2 3 4 5 6 7 8 9 10 

result:

wrong answer 1st numbers differ - expected: '6', found: '10'