結果

問題 No.2978 Lexicographically Smallest and Largest Subarray
ユーザー tnakao0123
提出日時 2024-12-05 19:55:02
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 191 ms / 2,000 ms
コード長 1,102 bytes
コンパイル時間 387 ms
コンパイル使用メモリ 41,328 KB
最終ジャッジ日時 2025-02-26 11:08:52
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 57
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int query(int, int, int, int)’:
main.cpp:28:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   28 |   scanf("%d", &x);
      |   ~~~~~^~~~~~~~~~
main.cpp: In function ‘int main()’:
main.cpp:37:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   37 |   scanf("%d%d", &n, &qn);
      |   ~~~~~^~~~~~~~~~~~~~~~~

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 2978.cc:  No.2978 Lexicographically Smallest and Largest Subarray - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<algorithm>

using namespace std;

/* constant */

const int MAX_N = 1000;
const int MAX_QN = 1500;

/* typedef */

/* global variables */

int as[MAX_N], bs[MAX_N];

/* subroutines */

int query(int l0, int r0, int l1, int r1) {
  printf("? %d %d %d %d\n", l0 + 1, r0, l1 + 1, r1); fflush(stdout);
  int x;
  scanf("%d", &x);
  if (x < 0) exit(0);
  return x;
}

/* main */

int main() {
  int n, qn;
  scanf("%d%d", &n, &qn);
  
  int m = n / 2;
  for (int i = 0, j = m; i < m; i++, j++) {
    if (query(i, n, j, n)) as[i] = i, bs[i] = j;
    else as[i] = j, bs[i] = i;
  }

  int mini = as[0];
  for (int i = 1; i < m; i++)
    if (query(as[i], as[i] + 1, mini, mini + 1)) mini = as[i];

  int maxi = bs[m - 1];
  for (int i = m - 2; i >= 0; i--)
    if (! query(bs[i], n, maxi, n)) maxi = bs[i];
	      
  printf("! %d %d %d %d\n", mini + 1, mini + 1, maxi + 1, n);
  fflush(stdout);

  //for (int i = 0; i < 1000000000; i++);
  return 0;
}
0