Submission #1871762
Source Code Expand
#include<bits/stdc++.h>
#define sqr(x) ((x)*(x))
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define ld long double
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define debuge cerr<<"isok"<<endl
#define debug(x) cerr<<#x<<"="<<x<<endl
#define SS second
#define FF first
#define ls (k<<1)
#define rs (k<<1|1)
#define inf 0x3f3f3f3f
#define clr(a,x) memset(a,x,sizeof(a))
#define cpy(a,x) memcpy(a,x,sizeof(a))
#define file(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout);
using namespace std;
const int N=305,M=100005,mod=1e9+7;
template<class T> inline void gmin(T &x,const T &y){if(x>y) x=y;}
template<class T> inline void gmax(T &x,const T &y){if(x<y) x=y;}
inline void ch(int &x,int y){x=(x+y)%mod;}
template<class T>inline void read(T &x){
x=0;char ch=getchar(),rev=0;
while(ch>'9'||ch<'0') rev=(ch=='-'),ch=getchar();
while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
x=rev?-x:x;
}
template<class T>inline void print(T x,const char c){
if(!x){putchar('0');putchar(c);return;}
if(x<0) putchar('-'),x=-x;
int m=0,a[10];
while(x) a[m++]=x%10,x/=10;
while(m--) putchar(a[m]+'0');
putchar(c);
}
inline int exp(int x,int y){
int ans=1;
while(y){
if(y&1) ans=(ll)ans*x%mod;
x=(ll)x*x%mod;y>>=1;
}return ans;
}
int n,m,now[N],a[N][N],du[N];
bool vis[N];
queue<int> q;
bool check(int k){
clr(vis,0);clr(du,0);
// if(x>1) return 1;
while(!q.empty()) q.pop();
for(int i=1;i<=n;i++){
du[a[i][1]]++;now[i]=1;
if(du[a[i][1]]==k+1) q.push(a[i][1]);
}
while(!q.empty()){
int x=q.front();q.pop();
vis[x]=1;
for(int i=1;i<=n;i++){
if(a[i][now[i]]!=x) continue;
while(now[i]<=m&&vis[a[i][now[i]]]) now[i]++;
if(now[i]>m) return 0;
du[a[i][now[i]]]++;
// debug(a[i][now[i]]);
if(du[a[i][now[i]]]==k+1){
q.push(a[i][now[i]]);
// debug(a[i][now[i]]);
}
}
}
// for(int i=1;i<=m;i++)printf("%d ",du[i]);puts("");
return 1;
}
int main(){
#ifdef rqgao2014
freopen("input.txt","r",stdin);
#endif
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
scanf("%d",&a[i][j]);
int l=1,r=n;
while(l<r){
int mid=l+r>>1;
if(check(mid)) r=mid; else l=mid+1;
}
printf("%d\n",r);
return 0;
}
Submission Info
Submission Time
2017-12-15 12:18:27+0900
Task
B - Sports Festival
User
rqgao2014
Language
C++14 (GCC 5.4.1)
Score
700
Code Size
2334 Byte
Status
AC
Exec Time
12 ms
Memory
640 KB
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:83:21: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&n,&m);
^
./Main.cpp:86:24: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&a[i][j]);
^
Judge Result
Set Name
Sample
All
Score / Max Score
0 / 0
700 / 700
Status
Set Name
Test Cases
Sample
sample_01.txt, sample_02.txt, sample_03.txt
All
sample_01.txt, sample_02.txt, sample_03.txt, sample_01.txt, sample_02.txt, sample_03.txt, subtask_1_01.txt, subtask_1_02.txt, subtask_1_03.txt, subtask_1_04.txt, subtask_1_05.txt, subtask_1_06.txt, subtask_1_07.txt, subtask_1_08.txt, subtask_1_09.txt, subtask_1_10.txt, subtask_1_11.txt, subtask_1_12.txt, subtask_1_13.txt, subtask_1_14.txt, subtask_1_15.txt, subtask_1_16.txt, subtask_1_17.txt, subtask_1_18.txt
Case Name
Status
Exec Time
Memory
sample_01.txt
AC
1 ms
256 KB
sample_02.txt
AC
1 ms
256 KB
sample_03.txt
AC
1 ms
256 KB
subtask_1_01.txt
AC
1 ms
256 KB
subtask_1_02.txt
AC
1 ms
384 KB
subtask_1_03.txt
AC
2 ms
256 KB
subtask_1_04.txt
AC
2 ms
384 KB
subtask_1_05.txt
AC
1 ms
384 KB
subtask_1_06.txt
AC
3 ms
640 KB
subtask_1_07.txt
AC
4 ms
640 KB
subtask_1_08.txt
AC
2 ms
640 KB
subtask_1_09.txt
AC
1 ms
640 KB
subtask_1_10.txt
AC
2 ms
256 KB
subtask_1_11.txt
AC
3 ms
384 KB
subtask_1_12.txt
AC
1 ms
256 KB
subtask_1_13.txt
AC
3 ms
384 KB
subtask_1_14.txt
AC
9 ms
640 KB
subtask_1_15.txt
AC
12 ms
640 KB
subtask_1_16.txt
AC
9 ms
640 KB
subtask_1_17.txt
AC
9 ms
640 KB
subtask_1_18.txt
AC
11 ms
640 KB