fork download
  1. /*
  2.   Author: Nguyen Nhut Truong
  3.   From Chuyen Tien Giang High School For The Gifed
  4. */
  5. #include <bits/stdc++.h>
  6. using namespace std;
  7.  
  8. //#define int long long
  9. #define start signed main
  10. #define fi first
  11. #define se second
  12. #define pb push_back
  13. #define eb emplace_back
  14. #define il pair<int,ll>
  15. #define ii pair<int,int>
  16. #define len(s) (int)s.size()
  17. #define all(s) (s).begin(),(s).end()
  18. #define OpenFile(Name) if (fopen(Name".inp","r")) freopen(Name".inp","r",stdin),freopen(Name".out","w",stdout);
  19.  
  20. #define MASK(x) ((1LL)<<(x))
  21. #define Bit(x,i) (((x)>>(i))&1)
  22. #define Countbit(x) __builtin_popcountll(x)
  23.  
  24. typedef long long ll;
  25. typedef long double ld;
  26.  
  27. int dx[]={1,-1,0,0,-1,1,1,-1};
  28. int dy[]={0,0,1,-1,-1,-1,1,1};
  29.  
  30. template <class C> bool Minimize(C &a, C b) { if (a>b) { a=b; return true; } return false;}
  31. template <class C> bool Maximize(C &a, C b) { if (a<b) { a=b; return true; } return false;}
  32.  
  33. inline ll add(ll a,ll b,ll c) { return (a+b)%c; };
  34. inline ll sub(ll a,ll b,ll c) { return (a-b+c)%c; };
  35. inline ll mul(ll a,ll b,ll c) { return ((a%c)*(b%c))%c; };
  36.  
  37. mt19937_64 rd(chrono::steady_clock::now().time_since_epoch().count());
  38.  
  39. ll rand(ll l,ll r){
  40. assert(l<=r);
  41. return l+rd()%(r-l+1);
  42. }
  43.  
  44. void MakeInp() {
  45. ofstream cout("Task.inp");
  46.  
  47. cout.close();
  48. }
  49.  
  50. /// Constant Limit
  51.  
  52. const int N=1e6+5,M=1e3+30,INF=1e9,lim=1e6;
  53. const int block=448,base=31;
  54.  
  55. ll Mod=1e9+7,Mod_base=1777777777,LNF=1e18;
  56.  
  57. ///____________________________________________________________________________________________________________________________
  58.  
  59.  
  60. int c,n,m;
  61. ll pre[M][M],a[M][M];
  62.  
  63. int check(int x1,int y1,int x2,int y2) {
  64. vector<int> v;
  65. for (int i=x1;i<=x2;++i) v.pb(pre[i][y2]-pre[i][y1-1]);
  66.  
  67. sort(all(v));
  68. int d=v[1]-v[0];
  69. if(d==0) return -1;
  70.  
  71. for (int i=1;i<len(v);++i)
  72. if(v[i]-v[i-1]!=d) return -1;
  73.  
  74. return d;
  75. }
  76.  
  77. bool f=0;
  78. void print(int x1,int y1,int x2,int y2,int d) {
  79. if (f) cout<<'\n';
  80. f=1;
  81.  
  82. cout<<'('<<x1<<','<<y1<<','<<x2<<','<<y2<<','<<d<<')';
  83. }
  84.  
  85. void Try(int x1,int y1,int x2,int y2) {
  86. if (x1==x2 || y1==y2) {
  87. print(x1,y1,x2,y2,0);
  88. return ;
  89. } else
  90. {
  91. int d=check(x1,y1,x2,y2);
  92. if(d!=-1) {
  93. print(x1,y1,x2,y2,d);
  94. return;
  95. }
  96. }
  97.  
  98. int x3=(x1+x2)/2;
  99. int y3=(y1+y2)/2;
  100.  
  101. if (f) cout<<'\n';
  102.  
  103. f=0;
  104. cout<<'(';
  105. Try(x1,y1,x3,y3);
  106. Try(x1,y3+1,x3,y2);
  107. Try(x3+1,y1,x2,y3);
  108. Try(x3+1,y3+1,x2,y2);
  109. cout<<')';
  110.  
  111. f=1;
  112. }
  113.  
  114. ll d[M],b[M];
  115.  
  116. start() {
  117. ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  118. OpenFile("TASK");
  119.  
  120. cin>>c>>n>>m;
  121.  
  122. if (c==1) {
  123. ll res=-LNF;
  124. for (int i=1;i<=n;++i) {
  125. ll ans=0;
  126. for (int i=1;i<=m;++i) {
  127. ll x; cin>>x;
  128. ans+=x;
  129. }
  130. d[i]=ans;
  131. Maximize(res,ans);
  132. }
  133.  
  134. for (int i=1;i<=n;++i)
  135. if (d[i]==res) cout<<i<<'\n';
  136.  
  137. return 0;
  138. } else
  139. if (c==2) {
  140. for (int i=1;i<=n;++i) {
  141. ll r;
  142. for (int i=1;i<=m;++i) cin>>b[i];
  143.  
  144. sort(b+1,b+m+1);
  145. if (m<3) {
  146. d[i]=1;
  147. } else {
  148. r=b[2]-b[1];
  149. for (int i=2;i<=m;++i)
  150. if (b[i]-b[i-1]!=r) {
  151. r=0;
  152. break;
  153. }
  154.  
  155. if (r!=0) d[i]=1;
  156. }
  157. }
  158.  
  159. for (int i=1;i<=n;++i)
  160. if (d[i]==1) cout<<i<<'\n';
  161. } else
  162. if (c==3) {
  163. for (int i=1;i<=n;++i)
  164. for (int j=1;j<=m;++j) {
  165. cin>>a[i][j];
  166. pre[i][j]=pre[i][j-1]+a[i][j];
  167. }
  168.  
  169. Try(1,1,n,m);
  170. }
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178. //cerr<<"\nBien dich thanh cong\nTime: "<<(1.0*clock()/CLOCKS_PER_SEC)<<" s\n";
  179. return 0;
  180. }
  181.  
Success #stdin #stdout 0s 5300KB
stdin
Standard input is empty
stdout
Standard output is empty