Rating changes for the last round are temporarily rolled back. They will be returned soon. ×

 
 
 
 
General
 
 
# Author Problem Lang Verdict Time Memory Sent Judged  
128694646 Practice:
ayush2800
1566D2 - 71 GNU C++17 Wrong answer on test 2 15 ms 4304 KB 2021-09-13 08:10:15 2021-09-13 08:10:15
 
 
→ Source
#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
const long long mod=1e9+7;
void print(vector<ll>&a)
{
    for(ll i=0;i<a.size();i++)
    {
        cout<<a[i]<<" ";
    }
    cout<<endl;
}
void get(vector<ll>&a,ll n)
{
    for(ll i=0;i<n;i++)
    {
        int j;
        cin>>j;
        a.push_back(j);
    }
}
void solve()
{
    int n,m;
    cin>>n>>m;
    vector<int>a(n*m,0);
    for(int i=0;i<n*m;i++)
    {
        cin>>a[i];
    }
    vector<int>b=a;
    sort(a.begin(),a.end());
    vector<vector<int>>v(n,vector<int>(m,0));
    int k=0;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            v[i][j]=a[k++];
        }
    }
    unordered_map<int,stack<pair<int,int>>>ma;
    for(int i=0;i<m;i++)
    {
        for(int j=n-1;j>=0;j--)
        {
            ma[v[j][i]].push({j,i});
        }
    }
    vector<vector<int>>vis(n,vector<int>(m,0));
    int sum=0;
    for(int i=0;i<n*m;i++)
    {
        pair<int,int>p=ma[b[i]].top();
        ma[b[i]].pop();
        int count=0;
        for(int i=0;i<p.second;i++)
        {
            if(vis[p.first][i])
            {
                count++;
            }
        }
        vis[p.first][p.second]=1;
        sum+=count;
    }
    cout<<sum<<endl;
}
int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    // generate(100);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    long long n=1;
    cin>>n;
    int g=n;
    while(n--)
    {
        solve();
    }
}    
 
 
?
Time: ? ms, memory: ? KB
Verdict: ?
Input
?
Participant's output
?
Jury's answer
?
Checker comment
?
Diagnostics
?
Click to see test details