제출 #736136

#제출 시각아이디문제언어결과실행 시간메모리
736136marvinthangNivelle (COCI20_nivelle)C++17
110 / 110
46 ms644 KiB
/******************************
*    author : @marvinthang    *
*    date : 10 / 02 / 2022    *
******************************/

#include <bits/stdc++.h>

using namespace std;

#define  superspeed  ios_base::sync_with_stdio(false); cin.tie(nullptr); // cout.tie(nullptr);
#define  file(name)  if (fopen (name".inp", "r")) { freopen (name".inp", "r", stdin); freopen (name".out", "w", stdout); }

template <class U, class V> ostream & operator << (ostream& out, const pair<U, V> &p) { return out << '(' << p.first << ", " << p.second << ')'; }
template <class T> ostream & operator << (ostream &out, const vector<T> &vt) { out << '{'; for (size_t i = 0; i + 1 < vt.size(); i++) out << vt[i] << ", "; if (!vt.empty()) out << vt.back(); return out << '}'; }

const 		int MOD = 1e9 + 7;
const     double PI = 3.1415926535897932384626433832795; // acos(-1.0); atan(-1.0);
const     int dir[] = {0, 1, 0, -1, 0}; // {0, 1, 1, -1, -1, 1, 0, -1, 0};
const  long long oo = 1e18;
const       int MAX = 1e5 + 5;

int N, last[26], tmp[27];
string S;

int main(void) {
    superspeed;
    file("coci1920_r4_nivelle");
    cin >> N >> S;
   	int resL = -1, resR = -1, res = 26;
   	memset(last, -1, sizeof(last));
   	tmp[26] = -1;
    for (int i = 0; i < N; ++i) {
    	int c = S[i] - 'a';	
    	last[c] = i;
    	for (int j = 0; j < 26; ++j) tmp[j] = last[j];
    	sort(tmp, tmp + 26, greater<int> ());

    	for (int j = 1; j <= 26; ++j) {
    		if (res * (i - tmp[j]) > j * (resR - resL + 1)) {
    			resL = tmp[j] + 1;
    			resR = i;
    			res = j;
    		}
    	}
    }
    cout << resL + 1 << ' ' << resR + 1 << '\n';
    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

nivelle.cpp: In function 'int main()':
nivelle.cpp:11:61: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 | #define  file(name)  if (fopen (name".inp", "r")) { freopen (name".inp", "r", stdin); freopen (name".out", "w", stdout); }
      |                                                     ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
nivelle.cpp:27:5: note: in expansion of macro 'file'
   27 |     file("coci1920_r4_nivelle");
      |     ^~~~
nivelle.cpp:11:95: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 | #define  file(name)  if (fopen (name".inp", "r")) { freopen (name".inp", "r", stdin); freopen (name".out", "w", stdout); }
      |                                                                                       ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
nivelle.cpp:27:5: note: in expansion of macro 'file'
   27 |     file("coci1920_r4_nivelle");
      |     ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...