Submission #3041798


Source Code Expand

#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
using namespace std;


typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(v) (v).rbegin(),(v).rend()
#define PB push


#define MOD 1000000009LL
#define EPS 1e-8

int R, C, K, N;
int r[ 100010 ];
int c[ 100010 ];
int rCnt[ 100010 ];
int cCnt[ 100010 ];
map<int, map<int, bool> > rc;
map<int, vector<int> > rByCnt;
map<int, vector<int> > cByCnt;

int main()
{
	cin >> R >> C >> K >> N;
	REP( i, N )
	{
		cin >> r[ i ] >> c[ i ];
		++rCnt[ r[ i ] ];
		++cCnt[ c[ i ] ];

		if( rc.count( r[ i ] ) == 0 )
		{
			map<int, bool> m;
			m.insert( make_pair( c[ i ], true ) );
			rc.insert( make_pair( r[ i ], m ) );
		}
		else
		{
			rc.at( r[ i ] ).insert( make_pair( c[ i ], true ) );
		}
	}

	for( int i = 1; i <= N; ++i )
	{
		if( rCnt[ i ] > 0 )
		{
			if( rByCnt.count( rCnt[ i ] ) == 0 )
			{
				vector<int> v;
				v.push_back( i );
				rByCnt.insert( make_pair( rCnt[ i ], v ) );
			}
			else
			{
				rByCnt.at( rCnt[ i ] ).push_back( i );
			}
		}
		if( cCnt[ i ] > 0 )
		{
			if( cByCnt.count( cCnt[ i ] ) == 0 )
			{
				vector<int> v;
				v.push_back( i );
				cByCnt.insert( make_pair( cCnt[ i ], v ) );
			}
			else
			{
				cByCnt.at( cCnt[ i ] ).push_back( i );
			}
		}
	}

	int ans = 0;
	for( auto entry : rByCnt )
	{
		int myCnt = entry.first;
		for( auto i : entry.second )
		{
			int oppCnt = K - myCnt;
			if( oppCnt >= 0 && cByCnt.count( oppCnt ) > 0 )
			{
				for( auto j : cByCnt.at( oppCnt ) )
				{
					if( rc.at( i ).count( j ) == 0 )
					{
						// printf( "(%d, %d)\n", i, j );
						++ans;
					}
				}
			}

			++oppCnt;
			if( oppCnt >= 0 && cByCnt.count( oppCnt ) > 0 )
			{
				for( auto j : cByCnt.at( oppCnt ) )
				{
					if( rc.at( i ).count( j ) > 0 )
					{
						// printf( "(%d, %d)\n", i, j );
						++ans;
					}
				}
			}
		}
	}

	cout << ans << endl;

	return 0;
}

Submission Info

Submission Time
Task C - 収集王
User keitanxkeitan
Language C++14 (GCC 5.4.1)
Score 0
Code Size 2984 Byte
Status WA
Exec Time 2104 ms
Memory 15224 KB

Judge Result

Set Name Sample Subtask1 Subtask2
Score / Max Score 0 / 0 0 / 30 0 / 70
Status
AC × 3
AC × 6
WA × 12
AC × 12
WA × 15
TLE × 6
Set Name Test Cases
Sample subtask0-sample01.txt, subtask0-sample02.txt, subtask0-sample03.txt
Subtask1 subtask0-sample01.txt, subtask0-sample02.txt, subtask0-sample03.txt, subtask1-01.txt, subtask1-02.txt, subtask1-03.txt, subtask1-04.txt, subtask1-05.txt, subtask1-06.txt, subtask1-07.txt, subtask1-08.txt, subtask1-09.txt, subtask1-10.txt, subtask1-11.txt, subtask1-12.txt, subtask1-13.txt, subtask1-14.txt, subtask1-15.txt
Subtask2 subtask0-sample01.txt, subtask0-sample02.txt, subtask0-sample03.txt, subtask1-01.txt, subtask1-02.txt, subtask1-03.txt, subtask1-04.txt, subtask1-05.txt, subtask1-06.txt, subtask1-07.txt, subtask1-08.txt, subtask1-09.txt, subtask1-10.txt, subtask1-11.txt, subtask1-12.txt, subtask1-13.txt, subtask1-14.txt, subtask1-15.txt, subtask2-01.txt, subtask2-02.txt, subtask2-03.txt, subtask2-04.txt, subtask2-05.txt, subtask2-06.txt, subtask2-07.txt, subtask2-08.txt, subtask2-09.txt, subtask2-10.txt, subtask2-11.txt, subtask2-12.txt, subtask2-13.txt, subtask2-14.txt, subtask2-15.txt
Case Name Status Exec Time Memory
subtask0-sample01.txt AC 1 ms 256 KB
subtask0-sample02.txt AC 1 ms 256 KB
subtask0-sample03.txt AC 1 ms 256 KB
subtask1-01.txt WA 1 ms 256 KB
subtask1-02.txt WA 1 ms 256 KB
subtask1-03.txt WA 1 ms 256 KB
subtask1-04.txt WA 1 ms 256 KB
subtask1-05.txt WA 1 ms 256 KB
subtask1-06.txt AC 1 ms 256 KB
subtask1-07.txt AC 1 ms 256 KB
subtask1-08.txt WA 1 ms 256 KB
subtask1-09.txt WA 1 ms 256 KB
subtask1-10.txt WA 1 ms 256 KB
subtask1-11.txt WA 1 ms 256 KB
subtask1-12.txt AC 1 ms 256 KB
subtask1-13.txt WA 1 ms 256 KB
subtask1-14.txt WA 1 ms 256 KB
subtask1-15.txt WA 1 ms 256 KB
subtask2-01.txt AC 2 ms 384 KB
subtask2-02.txt WA 3 ms 512 KB
subtask2-03.txt AC 24 ms 2048 KB
subtask2-04.txt AC 76 ms 6780 KB
subtask2-05.txt AC 93 ms 6528 KB
subtask2-06.txt TLE 2104 ms 13304 KB
subtask2-07.txt AC 79 ms 5760 KB
subtask2-08.txt TLE 2104 ms 13308 KB
subtask2-09.txt TLE 2104 ms 15224 KB
subtask2-10.txt TLE 2104 ms 13308 KB
subtask2-11.txt TLE 2104 ms 13180 KB
subtask2-12.txt WA 328 ms 13184 KB
subtask2-13.txt AC 117 ms 13308 KB
subtask2-14.txt TLE 2104 ms 13304 KB
subtask2-15.txt WA 910 ms 13184 KB